PREFIX math: <http://www.w3.org/2000/10/swap/math#>
PREFIX list: <http://www.w3.org/2000/10/swap/list#>
PREFIX func: <http://www.w3.org/2007/rif-builtin-function#>
PREFIX e: <http://eulersharp.sourceforge.net/2003/03swap/log-rules#>
PREFIX seq: <http://josd.github.io/eye/reasoning/seq#>
PREFIX string: <http://www.w3.org/2000/10/swap/string#>
PREFIX r: <http://www.w3.org/2000/10/swap/reason#>

[] a r:Proof, r:Conjunction;
  r:component <#lemma1>;
  r:gives {
    (1 2 3 4 6 9 10 11 13) seq:answer "1-4, 6, 9-11, 13".
  }.

<#lemma1> a r:Inference;
  r:gives {
    (1 2 3 4 6 9 10 11 13) seq:answer "1-4, 6, 9-11, 13".
  };
  r:evidence (
    <#lemma2>
    [ a r:Fact; r:gives {((1 "-" 4 ", ") (6 ", ") (9 "-" 11 ", ") (13 ", ")) list:append (1 "-" 4 ", " 6 ", " 9 "-" 11 ", " 13 ", ")}]
    [ a r:Fact; r:gives {((1 "-" 4 ", " 6 ", " 9 "-" 11 ", " 13) (", ")) list:append (1 "-" 4 ", " 6 ", " 9 "-" 11 ", " 13 ", ")}]
    [ a r:Fact; r:gives {(1 "-" 4 ", " 6 ", " 9 "-" 11 ", " 13) string:concatenation "1-4, 6, 9-11, 13"}]
  );
  r:rule <#lemma3>.

<#lemma2> a r:Inference;
  r:gives {
    (1 2 3 4 6 9 10 11 13) seq:punctuate ((1 "-" 4 ", ") (6 ", ") (9 "-" 11 ", ") (13 ", ")).
  };
  r:evidence (
    [ a r:Fact; r:gives {((1 "-" 4 ", ") (6 ", ") (9 "-" 11 ", ") (13 ", ")) e:firstRest ((1 "-" 4 ", ") ((6 ", ") (9 "-" 11 ", ") (13 ", ")))}]
    [ a r:Fact; r:gives {((1 2 3 4 6 9 10 11 13)) func:reverse (13 11 10 9 6 4 3 2 1)}]
    [ a r:Fact; r:gives {((13 11 10 9 6) (4 3 2 1)) list:append (13 11 10 9 6 4 3 2 1)}]
    <#lemma4>
    [ a r:Fact; r:gives {("!") e:derive true}]
    <#lemma5>
    [ a r:Fact; r:gives {((13 11 10 9 6)) func:reverse (6 9 10 11 13)}]
    <#lemma6>
  );
  r:rule <#lemma7>.

<#lemma3> a r:Extraction;
  r:gives {
    {(1 2 3 4 6 9 10 11 13) seq:punctuate ?x_0_1.
     ?x_0_1 list:append ?x_1_1.
     (?x_2_1 (", ")) list:append ?x_1_1.
     ?x_2_1 string:concatenation ?x_3_1} => {(1 2 3 4 6 9 10 11 13) seq:answer ?x_3_1}.
  };
  r:because [ a r:Parsing; r:source <http://josd.github.io/eye/reasoning/seq/seq_query.n3>].

<#lemma4> a r:Inference;
  r:gives {
    (4 3 2 1) seq:check true.
  };
  r:evidence (
    [ a r:Fact; r:gives {(4 3 2 1) e:firstRest (4 (3 2 1))}]
    [ a r:Fact; r:gives {(3 2 1) e:firstRest (3 (2 1))}]
    [ a r:Fact; r:gives {(3 1) math:sum 4}]
    <#lemma8>
  );
  r:rule <#lemma9>.

<#lemma5> a r:Inference;
  r:gives {
    (4 3 2 1) seq:format (1 "-" 4 ", ").
  };
  r:evidence (
    [ a r:Fact; r:gives {(4 3 2 1) e:firstRest (4 (3 2 1))}]
    [ a r:Fact; r:gives {(3 2 1) list:last 1}]
  );
  r:rule <#lemma10>.

<#lemma6> a r:Inference;
  r:gives {
    (6 9 10 11 13) seq:punctuate ((6 ", ") (9 "-" 11 ", ") (13 ", ")).
  };
  r:evidence (
    [ a r:Fact; r:gives {((6 ", ") (9 "-" 11 ", ") (13 ", ")) e:firstRest ((6 ", ") ((9 "-" 11 ", ") (13 ", ")))}]
    [ a r:Fact; r:gives {((6 9 10 11 13)) func:reverse (13 11 10 9 6)}]
    [ a r:Fact; r:gives {((13 11 10 9) (6)) list:append (13 11 10 9 6)}]
    <#lemma11>
    [ a r:Fact; r:gives {("!") e:derive true}]
    <#lemma12>
    [ a r:Fact; r:gives {((13 11 10 9)) func:reverse (9 10 11 13)}]
    <#lemma13>
  );
  r:rule <#lemma7>.

<#lemma7> a r:Extraction;
  r:gives {
    {?x_3_2 seq:punctuate ?x_0_2} <= {?x_0_2 e:firstRest (?x_1_2 ?x_2_2).
     (?x_3_2) func:reverse ?x_4_2.
     (?x_5_2 ?x_6_2) list:append ?x_4_2.
     ?x_6_2 seq:check true.
     ("!") e:derive true.
     ?x_6_2 seq:format ?x_1_2.
     (?x_5_2) func:reverse ?x_7_2.
     ?x_7_2 seq:punctuate ?x_2_2}.
  };
  r:because [ a r:Parsing; r:source <http://josd.github.io/eye/reasoning/seq/seq_components.n3>].

<#lemma8> a r:Inference;
  r:gives {
    (3 2 1) seq:check true.
  };
  r:evidence (
    [ a r:Fact; r:gives {(3 2 1) e:firstRest (3 (2 1))}]
    [ a r:Fact; r:gives {(2 1) e:firstRest (2 (1))}]
    [ a r:Fact; r:gives {(2 1) math:sum 3}]
    <#lemma14>
  );
  r:rule <#lemma9>.

<#lemma9> a r:Extraction;
  r:gives {
    {?x_0_3 seq:check true} <= {?x_0_3 e:firstRest (?x_1_3 ?x_2_3).
     ?x_2_3 e:firstRest (?x_3_3 ?x_4_3).
     (?x_3_3 1) math:sum ?x_1_3.
     ?x_2_3 seq:check true}.
  };
  r:because [ a r:Parsing; r:source <http://josd.github.io/eye/reasoning/seq/seq_components.n3>].

<#lemma10> a r:Extraction;
  r:gives {
    {?x_0_4 seq:format (?x_3_4 "-" ?x_1_4 ", ")} <= {?x_0_4 e:firstRest (?x_1_4 ?x_2_4).
     ?x_2_4 list:last ?x_3_4}.
  };
  r:because [ a r:Parsing; r:source <http://josd.github.io/eye/reasoning/seq/seq_components.n3>].

<#lemma11> a r:Inference;
  r:gives {
    (6) seq:check true.
  };
  r:evidence (
    [ a r:Fact; r:gives true]
  );
  r:rule <#lemma15>.

<#lemma12> a r:Inference;
  r:gives {
    (6) seq:format (6 ", ").
  };
  r:evidence (
    [ a r:Fact; r:gives true]
  );
  r:rule <#lemma16>.

<#lemma13> a r:Inference;
  r:gives {
    (9 10 11 13) seq:punctuate ((9 "-" 11 ", ") (13 ", ")).
  };
  r:evidence (
    [ a r:Fact; r:gives {((9 "-" 11 ", ") (13 ", ")) e:firstRest ((9 "-" 11 ", ") ((13 ", ")))}]
    [ a r:Fact; r:gives {((9 10 11 13)) func:reverse (13 11 10 9)}]
    [ a r:Fact; r:gives {((13) (11 10 9)) list:append (13 11 10 9)}]
    <#lemma17>
    [ a r:Fact; r:gives {("!") e:derive true}]
    <#lemma18>
    [ a r:Fact; r:gives {((13)) func:reverse (13)}]
    <#lemma19>
  );
  r:rule <#lemma7>.

<#lemma14> a r:Inference;
  r:gives {
    (2 1) seq:check true.
  };
  r:evidence (
    [ a r:Fact; r:gives {(2 1) e:firstRest (2 (1))}]
    [ a r:Fact; r:gives {(1) e:firstRest (1 ())}]
    [ a r:Fact; r:gives {(1 1) math:sum 2}]
    <#lemma20>
  );
  r:rule <#lemma9>.

<#lemma15> a r:Extraction;
  r:gives {
    {(?x_0_5) seq:check true} <= true.
  };
  r:because [ a r:Parsing; r:source <http://josd.github.io/eye/reasoning/seq/seq_components.n3>].

<#lemma16> a r:Extraction;
  r:gives {
    {(?x_0_6) seq:format (?x_0_6 ", ")} <= true.
  };
  r:because [ a r:Parsing; r:source <http://josd.github.io/eye/reasoning/seq/seq_components.n3>].

<#lemma17> a r:Inference;
  r:gives {
    (11 10 9) seq:check true.
  };
  r:evidence (
    [ a r:Fact; r:gives {(11 10 9) e:firstRest (11 (10 9))}]
    [ a r:Fact; r:gives {(10 9) e:firstRest (10 (9))}]
    [ a r:Fact; r:gives {(10 1) math:sum 11}]
    <#lemma21>
  );
  r:rule <#lemma9>.

<#lemma18> a r:Inference;
  r:gives {
    (11 10 9) seq:format (9 "-" 11 ", ").
  };
  r:evidence (
    [ a r:Fact; r:gives {(11 10 9) e:firstRest (11 (10 9))}]
    [ a r:Fact; r:gives {(10 9) list:last 9}]
  );
  r:rule <#lemma10>.

<#lemma19> a r:Inference;
  r:gives {
    (13) seq:punctuate ((13 ", ")).
  };
  r:evidence (
    [ a r:Fact; r:gives {((13 ", ")) e:firstRest ((13 ", ") ())}]
    [ a r:Fact; r:gives {((13)) func:reverse (13)}]
    [ a r:Fact; r:gives {(() (13)) list:append (13)}]
    <#lemma22>
    [ a r:Fact; r:gives {("!") e:derive true}]
    <#lemma23>
    [ a r:Fact; r:gives {(()) func:reverse ()}]
    <#lemma24>
  );
  r:rule <#lemma7>.

<#lemma20> a r:Inference;
  r:gives {
    (1) seq:check true.
  };
  r:evidence (
    [ a r:Fact; r:gives true]
  );
  r:rule <#lemma15>.

<#lemma21> a r:Inference;
  r:gives {
    (10 9) seq:check true.
  };
  r:evidence (
    [ a r:Fact; r:gives {(10 9) e:firstRest (10 (9))}]
    [ a r:Fact; r:gives {(9) e:firstRest (9 ())}]
    [ a r:Fact; r:gives {(9 1) math:sum 10}]
    <#lemma25>
  );
  r:rule <#lemma9>.

<#lemma22> a r:Inference;
  r:gives {
    (13) seq:check true.
  };
  r:evidence (
    [ a r:Fact; r:gives true]
  );
  r:rule <#lemma15>.

<#lemma23> a r:Inference;
  r:gives {
    (13) seq:format (13 ", ").
  };
  r:evidence (
    [ a r:Fact; r:gives true]
  );
  r:rule <#lemma16>.

<#lemma24> a r:Inference;
  r:gives {
    () seq:punctuate ().
  };
  r:evidence (
    [ a r:Fact; r:gives true]
  );
  r:rule <#lemma26>.

<#lemma25> a r:Inference;
  r:gives {
    (9) seq:check true.
  };
  r:evidence (
    [ a r:Fact; r:gives true]
  );
  r:rule <#lemma15>.

<#lemma26> a r:Extraction;
  r:gives {
    {() seq:punctuate ()} <= true.
  };
  r:because [ a r:Parsing; r:source <http://josd.github.io/eye/reasoning/seq/seq_components.n3>].

