diff --git a/UPolynomial.pas b/UPolynomial.pas index 4993c3f..13528ff 100644 --- a/UPolynomial.pas +++ b/UPolynomial.pas @@ -39,6 +39,7 @@ type property Coefficient[const AIndex: Integer]: TBigInt read GetCoefficient; function CalcValueAt(const AX: Int64): TBigInt; function IsEqualTo(const AOther: TBigIntPolynomial): Boolean; + function ScaleVariable(const AScaleFactor: TBigInt): TBigIntPolynomial; class function Create(const ACoefficients: array of TBigInt): TBigIntPolynomial; static; end; @@ -88,6 +89,26 @@ begin Result := False; end; +function TBigIntPolynomial.ScaleVariable(const AScaleFactor: TBigInt): TBigIntPolynomial; +var + len, i: Integer; + factor: TBigInt; +begin + if AScaleFactor <> TBigInt.Zero then + begin + len := Length(FCoefficients); + SetLength(Result.FCoefficients, len); + Result.FCoefficients[0] := FCoefficients[0]; + factor := AScaleFactor; + for i := 1 to len - 1 do begin + Result.FCoefficients[i] := FCoefficients[i] * factor; + factor := factor * AScaleFactor; + end; + end + else + SetLength(Result.FCoefficients, 0); +end; + class function TBigIntPolynomial.Create(const ACoefficients: array of TBigInt): TBigIntPolynomial; var high, i: integer;