Pythagorean Check

Recognizing a² + b² = c² from names alone, without a single number.

pythagorean-check.n3 · output · proof · check · try it in the playground


The question

Pythagoras’ theorem relates the sides of a right triangle: the square of a plus the square of b equals the square of c. Here we know nothing about lengths. We only know that a, b and c have squares, called a2, b2 and c2, and that a2 and b2 add up to c2.

Is that enough to say that a, b and c stand in Pythagoras’ relation?


What we tell Eyeron

:a :Square :a2 .
:b :Square :b2 .
:c :Square :c2 .
(:a2 :b2) :Add :c2 .

:Square and :Add are just names we made up; Eyeron does no arithmetic with them. (:a2 :b2) is a list, so the last line says “the pair a2, b2 adds up to c2”.

{
    ?A :Square ?A2 .
    ?B :Square ?B2 .
    ?C :Square ?C2 .
    (?A2 ?B2) :Add ?C2 .
} => {
    (?A ?B ?C) :Pythagoras true .
} .

The rule looks for this pattern of four statements and, when it finds it, concludes a statement about the list (?A ?B ?C). The program also has a rule that turns (:a :b :c) :Pythagoras true into itself, which adds nothing, and a query that asks for that one statement.


What Eyeron concludes

(:a :b :c) :Pythagoras true .

The pattern matched with A, B and C standing for a, b and c, in that order.


The proof, step by step

{ (:a :b :c) :Pythagoras true . }
  pe:rule 1;
  pe:binding
    [ pe:var "A"; pe:value :a ],
…
  pe:uses
    { :a :Square :a2 . },
    { :b :Square :b2 . },
    { :c :Square :c2 . },
    { (:a2 :b2) :Add :c2 . }.

{ :a :Square :a2 . }
  pe:fact "pythagorean-check.n3".

One rule step, citing rule 1 with all six variables bound, and four fact steps, one for each statement it used. The self-restating rule does not appear: the answer does not need it.


Checked: what the report says

# checked: 5 steps, 5 verified, 0 trusted
pe:verdict pe:checked;
pe:condition [ pe:id "C1"; pe:name "resolution"; pe:checked 5; pe:failed 0 ];
pe:condition [ pe:id "C10"; pe:name "call fidelity"; pe:checked 6; pe:failed 0 ].

All 5 steps were verified, so the verdict is checked.


Try it

eyeron examples/pythagorean-check.n3      # the answer
eyeron -p examples/pythagorean-check.n3   # with its proof
eyeron -c examples/pythagorean-check.n3   # the proof, checked

Change the last fact to (:b2 :a2) :Add :c2 . and the output is empty: the pattern now matches only with A and B swapped, so the query for (:a :b :c) finds nothing. Order in a list matters.


Takeaway

Rules match patterns, not meanings: give Eyeron the shape of Pythagoras’ relation and it recognizes it, with a proof, even with no numbers in sight.