Program Listing for File ilelement.h
↰ Return to documentation for file (core/include/lattice/ilelement.h
)
//==================================================================================
// BSD 2-Clause License
//
// Copyright (c) 2014-2023, NJIT, Duality Technologies Inc. and other contributors
//
// All rights reserved.
//
// Author TPOC: contact@openfhe.org
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//==================================================================================
/*
Represents and defines integer lattice element objects in OpenFHE
*/
#ifndef LBCRYPTO_INC_LATTICE_ILELEMENT_H
#define LBCRYPTO_INC_LATTICE_ILELEMENT_H
#include "math/discretegaussiangenerator.h"
#include "math/nbtheory.h"
#include "utils/exception.h"
#include "utils/inttypes.h"
#include "utils/serializable.h"
#include <vector>
namespace lbcrypto {
template <typename Element, typename VecType>
class ILElement : public Serializable {
using IntType = typename VecType::Integer;
public:
virtual Element Clone() const = 0;
virtual Element CloneEmpty() const = 0;
virtual Element CloneParametersOnly() const = 0;
virtual Element CloneWithNoise(const DiscreteGaussianGeneratorImpl<VecType>& dgg, Format format) const = 0;
virtual ~ILElement() = default;
// Assignment operators
virtual const Element& operator=(const Element& rhs) = 0;
virtual const Element& operator=(Element&& rhs) = 0;
virtual const Element& operator=(std::initializer_list<uint64_t> rhs) = 0;
// GETTERS
virtual Format GetFormat() const = 0;
virtual usint GetLength() const = 0;
virtual const IntType& GetModulus() const = 0;
virtual const VecType& GetValues() const = 0;
virtual usint GetCyclotomicOrder() const = 0;
virtual IntType& at(usint i) {
OPENFHE_THROW("at() not implemented");
}
virtual const IntType& at(usint i) const {
OPENFHE_THROW("const at() not implemented");
}
virtual IntType& operator[](usint i) {
OPENFHE_THROW("[] not implemented");
}
virtual const IntType& operator[](usint i) const {
OPENFHE_THROW("const [] not implemented");
}
// virtual NativePoly DecryptionCRTInterpolate(PlaintextModulus ptm) const
//= 0;
// OPERATORS
virtual Element operator-() const = 0;
virtual Element Plus(const IntType& element) const = 0;
virtual Element Minus(const IntType& element) const = 0;
virtual Element Times(const IntType& element) const = 0;
virtual Element Times(NativeInteger::SignedNativeInt element) const = 0;
virtual Element Plus(const Element& element) const = 0;
virtual Element Minus(const Element& element) const = 0;
virtual Element Times(const Element& element) const = 0;
// overloaded op= operators
virtual const Element& operator+=(const IntType& element) = 0;
virtual const Element& operator-=(const IntType& element) = 0;
virtual const Element& operator*=(const IntType& element) = 0;
virtual const Element& operator+=(const Element& element) = 0;
virtual const Element& operator-=(const Element& element) = 0;
virtual const Element& operator*=(const Element& element) = 0;
virtual bool operator==(const Element& element) const = 0;
inline bool operator!=(const Element& element) const {
return !(*this == element);
}
virtual void AddILElementOne() = 0;
virtual Element AutomorphismTransform(uint32_t i) const = 0;
virtual Element AutomorphismTransform(uint32_t i, const std::vector<uint32_t>& vec) const = 0;
virtual Element Transpose() const = 0;
virtual std::vector<Element> BaseDecompose(usint baseBits, bool evalModeAnswer) const = 0;
virtual Element DivideAndRound(const IntType& q) const = 0;
virtual bool InverseExists() const = 0;
virtual double Norm() const = 0;
virtual bool IsEmpty() const = 0;
virtual void MakeSparse(uint32_t wFactor) = 0;
virtual Element ModByTwo() const = 0;
virtual Element MultiplicativeInverse() const = 0;
virtual Element MultiplyAndRound(const IntType& p, const IntType& q) const = 0;
virtual std::vector<Element> PowersOfBase(usint baseBits) const = 0;
virtual Element Mod(const IntType& modulus) const = 0;
virtual void SwitchModulus(const IntType& modulus, const IntType& rootOfUnity, const IntType& modulusArb,
const IntType& rootOfUnityArb) = 0;
virtual void SwitchFormat() = 0;
inline void SetFormat(const Format format) {
if (this->GetFormat() != format) {
this->SwitchFormat();
}
}
};
} // namespace lbcrypto
#endif