预期类型“…”&引用;定义于。。。。。。。Ada中的错误

预期类型“…”&引用;定义于。。。。。。。Ada中的错误,ada,Ada,我用ADA编写了这样一个Karatsuba算法实现 procedure Karatsuba (Factor_1, Factor_2 : in Number; Product : out Number) is m : Integer; m2 : Integer; low1 : Number := (0,1); high1 : Number := (0,1); low2 : Number := (0,1); high2 :

我用ADA编写了这样一个Karatsuba算法实现

   procedure Karatsuba (Factor_1, Factor_2 : in Number; Product : out Number) is
      m : Integer;
      m2 : Integer;
      low1 : Number := (0,1);
      high1 : Number := (0,1);
      low2 : Number := (0,1);
      high2 : Number := (0,1);
      z0 : Index;
      z1 : Index;
      z2 : Index;
      x : Integer;
      y : Integer;
      hc1 : Index;
      hc2 : Index;
   begin
      low1 := (others => 0);
      high1 := (others => 0);
      low2 := (others => 0);
      high2 := (others => 0);  
      if Factor_1'Length = 1 or Factor_2'Length = 1 then
         Standard(Factor_1, Factor_2,Product);
      end if;
      -- calculates the size of the numbers
      m := Integer'Max(Factor_1'Length, Factor_2'Length);
      m2 := m / 2;
      -- split the digit sequences about the middle
      for Factor_1_Index in Factor_1'Range loop
         x := x + 1;
         if x <= m2 then
            low1(Factor_1_Index) := Factor_1(Factor_1_Index);
         else
            high1(hc1) := Factor_1(Factor_1_Index);
            hc1 := hc1 + 1;
         end if;
      end loop;
      for Factor_2_Index in Factor_2'Range loop
         y := y + 1;
         if y <= m2 then
            low2(Factor_2_Index) := Factor_2(Factor_2_Index);
         else
            high2(hc2) := Factor_2(Factor_2_Index);
            hc2 := hc2 + 1;
         end if;
      end loop;
      -- 3 calls made to numbers approximately half the size
      z0 := Karatsuba(low1, low2, Product);
      z1 := Karatsuba((low1 + high1), (low2 + high2), Product);
      z2 := Karatsuba(high1, high2, Product);
      Product := (z2*10**(2*m2))+((z1-z2-z0)*10**(m2))+(z0);
   end Karatsuba;
这是我分配了一些变量的另一个类:

package ITI8590.Natural_Number_Multiplication is

   type Digit  is range 0 .. 1;
   type Index  is new Positive;
   type Number is array (Index range <>) of Digit;

   for Digit'Size use 1;

   procedure Standard(Factor_1, Factor_2 : in Number; Product : out Number);
   procedure Karatsuba(Factor_1, Factor_2 : in Number; Product : out Number);

end ITI8590.Natural_Number_Multiplication;
包ITI8590.Natural\u Number\u乘法是
类型数字的范围为0。。1.
类型指数为新正;
类型编号是数字的数组(索引范围);
对于数字大小使用1;
程序标准(系数_1、系数_2:输入编号;产品:输出编号);
程序Karatsuba(系数1、系数2:输入编号;产品:输出编号);
结束ITI8590。自然数乘法;
为什么我会犯这个错误?我无法解决它,我陷入了困境。你能帮我吗


谢谢,

Karatsuba
是一个过程,因此在结尾处而不是

  z0 := Karatsuba(low1, low2, Product);
  z1 := Karatsuba((low1 + high1), (low2 + high2), Product);
  z2 := Karatsuba(high1, high2, Product);
应该是这样的

  Karatsuba(low1, low2, z0);
  Karatsuba((low1 + high1), (low2 + high2), z1);
  Karatsuba(high1, high2, z2);
这要求您将
z0
z1
z2
声明为
Number
,而不是
Index
。请注意,
Product
是过程的一个
out
参数,因此您所获得的所有代码都是用中间结果覆盖它两次(3次,包括对上述
标准
的调用)

但是你有一个问题:编译器说

yusuf.ada:25:12: unconstrained subtype not allowed (need initialization)
yusuf.ada:25:12: provide initial value or explicit array bounds
这要求与您声明的
low1
等方式相关:

  low1 : Number := (0,1);
  high1 : Number := (0,1);
  low2 : Number := (0,1);
  high2 : Number := (0,1);
这种方法的问题在于,您现在限制了变量的边界:
low1
被固定为有2个元素(设置为您随后覆盖的值),并且无法展开。我不知道算法应该如何工作,但这似乎不太可能是正确的;首先,如果输入超过2位,会发生什么情况

一种可能有效的方法是使用输入参数中的位数:

Max_Digits : constant Positive := Factor_1’Length + Factor_2’length;
pragma Assert (Product’Length >= Max_Digits, “possible overflow”);
low1 : Number (1 .. Max_Digits) := (others => 0);
等等


而且,正如ajb所评论的,您需要根据需要定义
+
-
*
**
数字
s和
整数
之间的运算符,特别是在表达式
(z2*10**(2*m2))+((z1-z2-z0)*10**(m2))+(z0)中
在程序的最后一行。

Karatsuba
是一个程序,因此在末尾而不是

  z0 := Karatsuba(low1, low2, Product);
  z1 := Karatsuba((low1 + high1), (low2 + high2), Product);
  z2 := Karatsuba(high1, high2, Product);
应该是这样的

  Karatsuba(low1, low2, z0);
  Karatsuba((low1 + high1), (low2 + high2), z1);
  Karatsuba(high1, high2, z2);
这要求您将
z0
z1
z2
声明为
Number
,而不是
Index
。请注意,
Product
是过程的一个
out
参数,因此您所获得的所有代码都是用中间结果覆盖它两次(3次,包括对上述
标准
的调用)

但是你有一个问题:编译器说

yusuf.ada:25:12: unconstrained subtype not allowed (need initialization)
yusuf.ada:25:12: provide initial value or explicit array bounds
这要求与您声明的
low1
等方式相关:

  low1 : Number := (0,1);
  high1 : Number := (0,1);
  low2 : Number := (0,1);
  high2 : Number := (0,1);
这种方法的问题在于,您现在限制了变量的边界:
low1
被固定为有2个元素(设置为您随后覆盖的值),并且无法展开。我不知道算法应该如何工作,但这似乎不太可能是正确的;首先,如果输入超过2位,会发生什么情况

一种可能有效的方法是使用输入参数中的位数:

Max_Digits : constant Positive := Factor_1’Length + Factor_2’length;
pragma Assert (Product’Length >= Max_Digits, “possible overflow”);
low1 : Number (1 .. Max_Digits) := (others => 0);
等等


而且,正如ajb所评论的,您需要根据需要定义
+
-
*
**
数字
s和
整数
之间的运算符,特别是在表达式
(z2*10**(2*m2))+((z1-z2-z0)*10**(m2))+(z0)中
在程序的最后一行。

Karatsuba
是一个程序,因此在末尾而不是

  z0 := Karatsuba(low1, low2, Product);
  z1 := Karatsuba((low1 + high1), (low2 + high2), Product);
  z2 := Karatsuba(high1, high2, Product);
应该是这样的

  Karatsuba(low1, low2, z0);
  Karatsuba((low1 + high1), (low2 + high2), z1);
  Karatsuba(high1, high2, z2);
这要求您将
z0
z1
z2
声明为
Number
,而不是
Index
。请注意,
Product
是过程的一个
out
参数,因此您所获得的所有代码都是用中间结果覆盖它两次(3次,包括对上述
标准
的调用)

但是你有一个问题:编译器说

yusuf.ada:25:12: unconstrained subtype not allowed (need initialization)
yusuf.ada:25:12: provide initial value or explicit array bounds
这要求与您声明的
low1
等方式相关:

  low1 : Number := (0,1);
  high1 : Number := (0,1);
  low2 : Number := (0,1);
  high2 : Number := (0,1);
这种方法的问题在于,您现在限制了变量的边界:
low1
被固定为有2个元素(设置为您随后覆盖的值),并且无法展开。我不知道算法应该如何工作,但这似乎不太可能是正确的;首先,如果输入超过2位,会发生什么情况

一种可能有效的方法是使用输入参数中的位数:

Max_Digits : constant Positive := Factor_1’Length + Factor_2’length;
pragma Assert (Product’Length >= Max_Digits, “possible overflow”);
low1 : Number (1 .. Max_Digits) := (others => 0);
等等


而且,正如ajb所评论的,您需要根据需要定义
+
-
*
**
数字
s和
整数
之间的运算符,特别是在表达式
(z2*10**(2*m2))+((z1-z2-z0)*10**(m2))+(z0)中
在程序的最后一行。

Karatsuba
是一个程序,因此在末尾而不是

  z0 := Karatsuba(low1, low2, Product);
  z1 := Karatsuba((low1 + high1), (low2 + high2), Product);
  z2 := Karatsuba(high1, high2, Product);
应该是这样的

  Karatsuba(low1, low2, z0);
  Karatsuba((low1 + high1), (low2 + high2), z1);
  Karatsuba(high1, high2, z2);
这要求您将
z0
z1
z2
声明为
Number
,而不是
Index
。请注意,
Product
是过程的一个
out
参数,因此您所获得的所有代码都是用中间结果覆盖它两次(3次,包括对上述
标准
的调用)

但是你有一个问题:编译器说

yusuf.ada:25:12: unconstrained subtype not allowed (need initialization)
yusuf.ada:25:12: provide initial value or explicit array bounds
这要求与您声明的
low1
等方式相关:

  low1 : Number := (0,1);
  high1 : Number := (0,1);
  low2 : Number := (0,1);
  high2 : Number := (0,1);
这种方法的问题在于,您现在限制了变量的边界:
low1
被固定为有2个元素(设置为您随后覆盖的值),并且无法展开。我不知道算法应该如何工作,但这似乎不太可能是正确的;首先,如果输入超过2位,会发生什么情况

一种可能有效的方法是使用输入参数中的位数:

Max_Digits : constant Positive := Factor_1’Length + Factor_2’length;
pragma Assert (Product’Length >= Max_Digits, “possible overflow”);
low1 : Number (1 .. Max_Digits) := (others => 0);
<