2013-11-04 2 views
0

에서 I 메이플에서 시험 Divison 알고리즘에 대한 다음과 같은 코드가 있습니다시험 Divison 알고리즘 메이플

TrialDivision := proc(n :: integer) 
    if n <= 1 then 
      false 
    elif n = 2 then 
      true 
    elif type(n, 'even') then 
      false 
    else 
      for local i from 3 by 2 while i * i <= n do 
       if irem(n,i) = 0 then 
         return false 
       end if 
      end do; 
      true 
    end if 
end proc: 

내가 http://rosettacode.org/wiki/Primality_by_trial_division#MATLAB에서 얻었다. 하지만 그것을 실행하려고하면 다음 오류가 발생합니다 : 오류, 예기치 않은 local 프로 시저 본문에 선언.

누구든지 내가 뭘 잘못하고 있는지 알아?

+0

이 도움말 페이지는 마지막 예제를 참조 메이플 시저의, 심지어 내부 시저의 http://www.maplesoft.com/support/help/Maple/view.aspx?path=examples/lexical을에 대한 유용한 정보가 포함되어 있습니다 페이지, 그것은 매우 흥미 롭습니다. – Nasser

답변

1

절차 본문 전체에 로컬 선언을 허용하는 것은 Maple 언어에 다소 최근에 추가 된 것입니다.

이렇게 변경할 수 있습니다.

TrialDivision := proc(n :: integer) 
    local i; 
    if n <= 1 then 
      false 
    elif n = 2 then 
      true 
    elif type(n, 'even') then 
     false 
    else 
      for i from 3 by 2 while i * i <= n do 
       if irem(n,i) = 0 then 
         return false 
       end if 
      end do; 
      true 
    end if 
end proc: