为什么在ada的contador中是oveflow?

为什么在ada的contador中是oveflow?,ada,Ada,我不知道为什么变量contador中溢出的prove是错误的。我需要帮助 contador: Integer; J: Integer; function noPrimos (lista : My_Array) return Boolean with Global => contador, --Depends => ..., Pre => True and contador < Integer'Last,

我不知道为什么变量contador中溢出的prove是错误的。我需要帮助

 contador: Integer;
   J: Integer;

   function noPrimos (lista : My_Array) return Boolean

   with
      Global  => contador,
      --Depends => ...,
      Pre     => True and contador < Integer'Last,
      Post    => (noPrimos'Result = True or noPrimos'Result = False);  



FILE ADB

function noPrimos (lista : My_Array)  return Boolean is
      contador: Integer;
   begin
      for I in lista'Range loop
         contador:= 0;
         if lista(I) /= 1 then
            for J in 1.. lista(I) loop
               if lista(I) rem J = 0 then
                  contador := contador + 1;
               end if;
            end loop;
            if contador <= 2 then
               return false;
            end if;
         else
            return true;
         end if;
         pragma Loop_Variant(Increases => I);
      end loop;
      return true;
   end noPrimos;  
contador:整数;
J:整数;
函数noPrimos(lista:My_数组)返回布尔值
具有
全球=>contador,
--取决于=>。。。,
Pre=>True和contador(noPrimos'Result=True或noPrimos'Result=False);
亚洲开发银行文件
函数noPrimos(lista:My_数组)返回的布尔值为
contador:整数;
开始
对于lista'Range循环中的I
contador:=0;
如果lista(I)/=1,则
对于1中的J。。lista(I)循环
如果lista(I)rem J=0,则
contador:=contador+1;
如果结束;
端环;
如果contador I);
端环;
返回true;
诺普里莫斯终点;
问题在于溢出,其结果是: 第1阶段(共2阶段):生成全球合同。。。 第2阶段,共2阶段:流量分析和验证。。。 15:40:中等:溢出检查可能失败(例如,当contador=2147483647时)
47:40:中等:溢出检查可能失败(例如,当contador=0时)

首先,我假设函数
noPrimos
仅在列表
lista
不包含任何素数时才会返回
True
。话虽如此,我对代码片段的某些方面感到有点困惑:

  • 缺少
    My_数组
    的类型定义

  • 在给定的代码片段中,
    contador
    (英文:counter)的全局实例的角色不清楚。通过编写
    Global=>contador
    ,您可以声明函数
    noPrimos
    将读取全局变量
    contador
    (另请参见),但这不会发生,因为
    contador
    的本地实例会隐藏
    contador
    的全局实例

  • 全局定义变量
    J
    的原因不清楚,您可以忽略它

  • 前提条件
    True
    (位于布尔运算符
    的左侧)很简单,可以省略

  • 后置条件表明,
    noPrimos
    的结果可以是
    True
    False
    。这很简单,因为
    noPrimos
    返回一个布尔值,因此可以省略。后置条件应说明给定输入的函数的预期结果

  • 循环变量
    pragma循环变量(增加=>I)是微不足道的,因为变量
    I
    将随着for循环的定义而增加。因此,可以省略循环变量

下面是一个函数
No_Primes
的示例,该函数在给定列表
L
中搜索Primes,如果没有找到,则返回
True
。它在GNAT CE 2019中证明:

primes.ads(规范)

小型测试程序(main.adb

屈服

No_Primes (L1) = TRUE
No_Primes (L2) = FALSE
No_Primes (L3) = FALSE
No_Primes (L4) = TRUE
No_Primes (L5) = TRUE
No_Primes (L6) = FALSE

首先,我假设函数
noPrimos
仅当列表
lista
不包含任何素数时才会返回
True
。话虽如此,我对代码片段的某些方面感到有点困惑:

  • 缺少
    My_数组
    的类型定义

  • 在给定的代码片段中,
    contador
    (英文:counter)的全局实例的角色不清楚。通过编写
    Global=>contador
    ,您可以声明函数
    noPrimos
    将读取全局变量
    contador
    (另请参见),但这不会发生,因为
    contador
    的本地实例会隐藏
    contador
    的全局实例

  • 全局定义变量
    J
    的原因不清楚,您可以忽略它

  • 前提条件
    True
    (位于布尔运算符
    的左侧)很简单,可以省略

  • 后置条件表明,
    noPrimos
    的结果可以是
    True
    False
    。这很简单,因为
    noPrimos
    返回一个布尔值,因此可以省略。后置条件应说明给定输入的函数的预期结果

  • 循环变量
    pragma循环变量(增加=>I)是微不足道的,因为变量
    I
    将随着for循环的定义而增加。因此,可以省略循环变量

下面是一个函数
No_Primes
的示例,该函数在给定列表
L
中搜索Primes,如果没有找到,则返回
True
。它在GNAT CE 2019中证明:

primes.ads(规范)

小型测试程序(main.adb

屈服

No_Primes (L1) = TRUE
No_Primes (L2) = FALSE
No_Primes (L3) = FALSE
No_Primes (L4) = TRUE
No_Primes (L5) = TRUE
No_Primes (L6) = FALSE

如果列表中的非素数不超过2个,或者列表中的任何成员为1,则似乎
noPrimos
返回
True
。很难想象有什么要求可以证明这样的后条件是合理的!如果列表中的非素数不超过2个,或者列表中的任何成员为1,则似乎
noPrimos
返回
True
。很难想象有什么要求可以证明这样的后条件是合理的!
with Ada.Text_IO; use Ada.Text_IO;
with Primes;      use Primes;

procedure Main is

   --  Some test vectors.
   L1 : List := (1 => 1);         --  Expect TRUE  : 1 is not a prime.
   L2 : List := (1, 2, 3, 5, 7);  --  Expect FALSE : All are prime except 1.
   L3 : List := (2, 3, 5, 7);     --  Expect FALSE : All are prime.
   L4 : List := (1, 4, 6, 8, 9);  --  Expect TRUE  : None are prime.
   L5 : List := (4, 6, 8, 9);     --  Expect TRUE  : None are prime.
   L6 : List := (3, 4, 5);        --  Expect FALSE : 3 and 5 are prime.

begin
   Put_Line ("No_Primes (L1) = " & Boolean'Image (No_Primes (L1)));
   Put_Line ("No_Primes (L2) = " & Boolean'Image (No_Primes (L2)));
   Put_Line ("No_Primes (L3) = " & Boolean'Image (No_Primes (L3)));
   Put_Line ("No_Primes (L4) = " & Boolean'Image (No_Primes (L4)));
   Put_Line ("No_Primes (L5) = " & Boolean'Image (No_Primes (L5)));
   Put_Line ("No_Primes (L6) = " & Boolean'Image (No_Primes (L6)));
end Main;
No_Primes (L1) = TRUE
No_Primes (L2) = FALSE
No_Primes (L3) = FALSE
No_Primes (L4) = TRUE
No_Primes (L5) = TRUE
No_Primes (L6) = FALSE