eyereasoner 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/eye.pl.js +1 -1
  2. package/package.json +3 -3
package/dist/eye.pl.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = void 0;
4
- var eye = "% --------------------------------------------\n% Euler Yet another proof Engine -- Jos De Roo\n% --------------------------------------------\n%\n% See http://github.com/eyereasoner/eye\n%\n\n:- use_module(library(lists)).\n:- use_module(library(gensym)).\n:- use_module(library(system)).\n:- use_module(library(terms)).\n:- use_module(library(url)).\n:- use_module(library(charsio)).\n:- use_module(library(qsave)).\n:- use_module(library(base64)).\n:- use_module(library(date)).\n:- use_module(library(prolog_jiti)).\n:- use_module(library(sha)).\n:- use_module(library(semweb/turtle)).\n:- catch(use_module(library(http/http_open)), _, true).\n\nversion_info('EYE v23.0106.2349 josd').\n\nlicense_info('MIT License\n\nCopyright (c) 2006-2022 Jos De Roo\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.').\n\nhelp_info('Usage: eye <options>* <data>* <query>*\neye\n swipl -g main eye.pl --\n<options>\n --blogic support RDF surfaces\n --csv-separator <separator> CSV separator such as , or ;\n --debug output debug info on stderr\n --debug-cnt output debug info about counters on stderr\n --debug-djiti output debug info about DJITI on stderr\n --debug-implies output debug info about implies on stderr\n --debug-models output debug info about models on stderr\n --debug-pvm output debug info about PVM code on stderr\n --help show help info\n --hmac-key <key> HMAC key used in e:hmac-sha built-in\n --ignore-inference-fuse do not halt in case of inference fuse\n --image <pvm-file> output all <data> and all code to <pvm-file>\n --intermediate <n3p-file> output all <data> to <n3p-file>\n --license show license info\n --max-inferences <nr> halt after maximum number of inferences\n --multi-query go into query answer loop\n --no-distinct-input no distinct triples in the input\n --no-distinct-output no distinct answers in the output\n --no-erase no erase functionality for blogic\n --no-numerals no numerals in the output\n --no-qnames no qnames in the output\n --no-qvars no qvars in the output\n --no-ucall no extended unifier for forward rules\n --nope no proof explanation\n --output <file> output reasoner output to <file>\n --profile output profile info on stderr\n --quantify <prefix> quantify uris with <prefix> in the output\n --quiet quiet mode\n --random-seed create random seed for e:random built-in\n --restricted restricting to core built-ins\n --rule-histogram output rule histogram info on stderr\n --skolem-genid <genid> use <genid> in Skolem IRIs\n --source <file> read command line arguments from <file>\n --statistics output statistics info on stderr\n --strings output log:outputString objects on stdout\n --tactic limited-answer <nr> give only a limited number of answers\n --tactic linear-select select each rule only once\n --version show version info\n --warn output warning info on stderr\n --wcache <uri> <file> to tell that <uri> is cached as <file>\n<data>\n [--n3] <uri> N3 triples and rules\n --n3p <uri> N3P intermediate\n --proof <uri> N3 proof lemmas\n --turtle <uri> Turtle triples\n<query>\n --entail <rdf-graph> output true if RDF graph is entailed\n --not-entail <rdf-graph> output true if RDF graph is not entailed\n --pass output deductive closure\n --pass-all output deductive closure plus rules\n --pass-all-ground ground the rules and run --pass-all\n --pass-only-new output only new derived triples\n --query <n3-query> output filtered with filter rules').\n\n:- dynamic(answer/3). % answer(Predicate, Subject, Object)\n:- dynamic(argi/1).\n:- dynamic(base_uri/1).\n:- dynamic(bcnd/2).\n:- dynamic(bgot/3).\n:- dynamic(brake/0).\n:- dynamic(bref/2).\n:- dynamic(bvar/1).\n:- dynamic(cc/1).\n:- dynamic(cpred/1).\n:- dynamic(data_fuse/0).\n:- dynamic(evar/3).\n:- dynamic(exopred/3). % exopred(Predicate, Subject, Object)\n:- dynamic(fact/1).\n:- dynamic(flag/1).\n:- dynamic(flag/2).\n:- dynamic(fpred/1).\n:- dynamic(got_dq/0).\n:- dynamic(got_head/0).\n:- dynamic(got_labelvars/3).\n:- dynamic(got_models/0).\n:- dynamic(got_pi/0).\n:- dynamic(got_random/3).\n:- dynamic(got_sq/0).\n:- dynamic(got_unique/2).\n:- dynamic(got_wi/5). % got_wi(Source, Premise, Premise_index, Conclusion, Rule)\n:- dynamic(got_uuid/1).\n:- dynamic(graph/2).\n:- dynamic(hash_value/2).\n:- dynamic(implies/3). % implies(Premise, Conclusion, Source)\n:- dynamic(input_statements/1).\n:- dynamic(intern/1).\n:- dynamic(keep_skolem/1).\n:- dynamic(lemma/6). % lemma(Count, Source, Premise, Conclusion, Premise-Conclusion_index, Rule)\n:- dynamic(model/3).\n:- dynamic(modelo/3).\n:- dynamic(mtime/2).\n:- dynamic(n3s/2).\n:- dynamic(ncllit/0).\n:- dynamic(ns/2).\n:- dynamic(pass_only_new/1).\n:- dynamic(pfx/2).\n:- dynamic(pred/1).\n:- dynamic(prfstep/7). % prfstep(Conclusion_triple, Premise, Premise_index, Conclusion, Rule, Chaining, Source)\n:- dynamic(qevar/3).\n:- dynamic(query/2).\n:- dynamic(quvar/3).\n:- dynamic(retwist/3).\n:- dynamic(rule_uvar/1).\n:- dynamic(scope/1).\n:- dynamic(scount/1).\n:- dynamic(semantics/2).\n:- dynamic(span/1).\n:- dynamic(tabl/3).\n:- dynamic(tmpfile/1).\n:- dynamic(tuple/2).\n:- dynamic(tuple/3).\n:- dynamic(tuple/4).\n:- dynamic(tuple/5).\n:- dynamic(tuple/6).\n:- dynamic(tuple/7).\n:- dynamic(tuple/8).\n:- dynamic(wcache/2).\n:- dynamic(wpfx/1).\n:- dynamic(wtcache/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#biconditional>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#call>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#conditional>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tactic>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'/2).\n:- dynamic('<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>'/2).\n:- dynamic('<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'/2).\n:- dynamic('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'/2).\n:- dynamic('<http://www.w3.org/2000/01/rdf-schema#subClassOf>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#callWithCleanup>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#implies>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#onNeutralSurface>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#outputString>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/reason#source>'/2).\n\n%\n% Main goal\n%\n\nmain(Argv) :-\n set_prolog_flag(argv, Argv),\n catch(run, Exc,\n ( Exc = halt(_)\n -> true\n ; throw(Exc)\n )\n ).\n\nmain :-\n catch(run, Exc,\n ( Exc = halt(EC)\n -> halt(EC)\n ; throw(Exc)\n )\n ).\n\nrun :-\n current_prolog_flag(version_data, swi(SV, _, _, _)),\n ( SV < 8\n -> format(user_error, '** ERROR ** EYE requires at least swipl version 8 **~n', []),\n flush_output(user_error),\n throw(halt(1))\n ; true\n ),\n catch(set_stream(user_output, encoding(utf8)), _, true),\n current_prolog_flag(argv, Argv),\n ( append(_, ['--'|Argvp], Argv)\n -> true\n ; Argvp = Argv\n ),\n ( Argvp = ['--source', File]\n -> ( File = '-'\n -> read_line_to_codes(user_input, Codes)\n ; read_file_to_codes(File, Codes, [])\n ),\n atom_codes(Atom, Codes),\n atomic_list_concat(Argvs, ' ', Atom)\n ; Argvs = Argvp\n ),\n argv(Argvs, Argus),\n findall(Argij,\n ( argi(Argij)\n ),\n Argil\n ),\n append(Argil, Argi),\n ( member('--quiet', Argus)\n -> true\n ; format(user_error, 'eye~@~@~n', [w0(Argi), w1(Argus)]),\n version_info(Version),\n format(user_error, '~w~n', [Version]),\n ( current_prolog_flag(version_git, PVersion)\n -> true\n ; current_prolog_flag(version_data, swi(Major, Minor, Patch, Options)),\n ( memberchk(tag(Tag), Options)\n -> atomic_list_concat([Major, '.', Minor, '.', Patch, '-', Tag], PVersion)\n ; atomic_list_concat([Major, '.', Minor, '.', Patch], PVersion)\n )\n ),\n format(user_error, 'SWI-Prolog version ~w~n', [PVersion]),\n flush_output(user_error)\n ),\n ( retract(prolog_file_type(qlf, qlf))\n -> assertz(prolog_file_type(pvm, qlf))\n ; true\n ),\n ( Argv = ['--n3', _]\n -> retractall(flag('parse-only')),\n assertz(flag('parse-only'))\n ; true\n ),\n catch(gre(Argus), Exc,\n ( Exc = halt(0)\n -> true\n ; ( flag('parse-only')\n -> true\n ; format(user_error, '** ERROR ** gre ** ~w~n', [Exc]),\n flush_output(user_error),\n nb_setval(exit_code, 3)\n )\n )\n ),\n ( flag(statistics)\n -> statistics\n ; true\n ),\n ( flag('debug-implies')\n -> mf(implies(_, _, _))\n ; true\n ),\n ( flag('debug-pvm')\n -> tell(user_error),\n ignore(vm_list(_)),\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n )\n ; true\n ),\n ( flag('debug-djiti')\n -> tell(user_error),\n jiti_list,\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n )\n ; true\n ),\n nb_getval(exit_code, EC),\n flush_output,\n throw(halt(EC)).\n\nargv([], []) :-\n !.\nargv([Arg|Argvs], [U, V|Argus]) :-\n sub_atom(Arg, B, 1, E, '='),\n sub_atom(Arg, 0, B, _, U),\n memberchk(U, ['--csv-separator', '--hmac-key', '--image', '--max-inferences', '--n3', '--n3p', '--proof', '--quantify', '--query', '--output', '--skolem-genid', '--tactic', '--turtle']),\n !,\n sub_atom(Arg, _, E, 0, V),\n argv(Argvs, Argus).\nargv([Arg|Argvs], [Arg|Argus]) :-\n argv(Argvs, Argus).\n\n\n% ------------------------------\n% GRE (Generic Reasoning Engine)\n% ------------------------------\n\ngre(Argus) :-\n statistics(runtime, [T0, _]),\n statistics(walltime, [T1, _]),\n ( member('--quiet', Argus)\n -> true\n ; format(user_error, 'starting ~w [msec cputime] ~w [msec walltime]~n', [T0, T1]),\n flush_output(user_error)\n ),\n nb_setval(entail_mode, false),\n nb_setval(exit_code, 0),\n nb_setval(indentation, 0),\n nb_setval(limit, -1),\n nb_setval(bnet, not_done),\n nb_setval(fnet, not_done),\n nb_setval(tabl, -1),\n nb_setval(tuple, -1),\n nb_setval(fdepth, 0),\n nb_setval(pdepth, 0),\n nb_setval(cdepth, 0),\n nb_setval(mconc, false),\n ( input_statements(Ist)\n -> nb_setval(input_statements, Ist)\n ; nb_setval(input_statements, 0)\n ),\n nb_setval(output_statements, 0),\n nb_setval(current_scope, '<>'),\n nb_setval(wn, 0),\n opts(Argus, Args),\n ( \\+flag('multi-query'),\n Args = []\n -> opts(['--help'], _)\n ; true\n ),\n ( flag('skolem-genid', Genid)\n -> true\n ; A is random(2^62),\n atom_number(Genid, A)\n ),\n atomic_list_concat(['http://eyereasoner.github.io/.well-known/genid/', Genid, '#'], Sns),\n nb_setval(var_ns, Sns),\n ( ( flag(strings)\n ; flag(image, _)\n )\n -> true\n ; version_info(Version),\n ( flag(quiet)\n -> true\n ; format('#Processed by ~w~n', [Version])\n ),\n findall(Argij,\n ( argi(Argij)\n ),\n Argil\n ),\n append(Argil, Argi),\n ( flag(quiet)\n -> true\n ; format('#eye~@~@~n~n', [w0(Argi), w1(Argus)]),\n flush_output\n )\n ),\n ( ( flag('no-qvars')\n ; flag('pass-all-ground')\n )\n -> retractall(pfx('var:', _)),\n assertz(pfx('var:', '<http://eyereasoner.github.io/var#>'))\n ; true\n ),\n ( flag(intermediate, Out)\n -> format(Out, 'flag(\\'quantify\\', \\'~w\\').~n', [Sns])\n ; true\n ),\n args(Args),\n ( implies(_, Conc, _),\n ( var(Conc)\n ; Conc \\= answer(_, _, _),\n Conc \\= (answer(_, _, _), _)\n )\n -> true\n ; ( \\+flag(image, _),\n \\+flag(tactic, 'linear-select')\n -> assertz(flag(tactic, 'linear-select'))\n ; true\n )\n ),\n findall(Sc,\n ( scope(Sc)\n ),\n Scope\n ),\n nb_setval(scope, Scope),\n statistics(runtime, [_, T2]),\n statistics(walltime, [_, T3]),\n ( flag(quiet)\n -> true\n ; format(user_error, 'networking ~w [msec cputime] ~w [msec walltime]~n', [T2, T3]),\n flush_output(user_error)\n ),\n nb_getval(input_statements, SC),\n ( flag(image, File)\n -> assertz(argi(Argus)),\n retractall(flag(image, _)),\n assertz(flag('quantify', Sns)),\n retractall(input_statements(_)),\n assertz(input_statements(SC)),\n reset_gensym,\n ( current_predicate(qsave:qsave_program/1)\n -> qsave_program(File)\n ; save_program(File)\n ),\n throw(halt(0))\n ; true\n ),\n ( flag(intermediate, Out)\n -> ( SC =\\= 0\n -> write(Out, scount(SC)),\n writeln(Out, '.')\n ; true\n ),\n writeln(Out, 'end_of_file.'),\n close(Out)\n ; true\n ),\n ( \\+implies(_, answer(_, _, _), _),\n \\+implies(_, (answer(_, _, _), _), _),\n \\+query(_, _),\n \\+flag('pass-only-new'),\n \\+flag('multi-query'),\n \\+flag(strings)\n -> throw(halt(0))\n ; true\n ),\n ( flag(nope)\n -> true\n ; ( pfx('r:', _)\n -> true\n ; assertz(pfx('r:', '<http://www.w3.org/2000/10/swap/reason#>'))\n ),\n ( pfx('var:', _)\n -> true\n ; assertz(pfx('var:', '<http://eyereasoner.github.io/var#>'))\n ),\n ( pfx('skolem:', _)\n -> true\n ; nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, '>'], B),\n assertz(pfx('skolem:', B))\n ),\n ( pfx('n3:', _)\n -> true\n ; assertz(pfx('n3:', '<http://www.w3.org/2004/06/rei#>'))\n )\n ),\n nb_setval(tr, 0),\n nb_setval(tc, 0),\n nb_setval(tp, 0),\n nb_setval(rn, 0),\n nb_setval(lemma_count, 0),\n nb_setval(lemma_cursor, 0),\n nb_setval(answer_count, 0),\n ( flag('multi-query')\n -> nb_setval(mq, 0),\n repeat,\n catch((read_line_to_codes(user_input, Fc), atom_codes(Fa, Fc)), _, Fa = end_of_file),\n ( atomic_list_concat([Fi, Fo], ', ', Fa)\n -> open(Fo, write, Fos, [encoding(utf8)])\n ; Fi = Fa,\n ( flag('output', Output)\n -> Fos = Output\n ; Fos = user_output\n )\n ),\n tell(Fos),\n ( Fi = end_of_file\n -> true\n ; statistics(walltime, [_, _]),\n nb_getval(output_statements, Outb),\n statistics(inferences, Infb),\n ( flag(blogic)\n -> Amq = ['--n3', Fi]\n ; Amq = ['--query', Fi]\n ),\n catch(args(Amq), Exc1,\n ( format(user_error, '** ERROR ** args ** ~w~n', [Exc1]),\n flush_output(user_error),\n nb_setval(exit_code, 3)\n )\n ),\n catch(eam(0), Exc2,\n ( ( Exc2 = halt(0)\n -> true\n ; format(user_error, '** ERROR ** eam ** ~w~n', [Exc2]),\n flush_output(user_error),\n ( Exc2 = inference_fuse(_)\n -> nb_setval(exit_code, 2)\n ; nb_setval(exit_code, 3)\n )\n )\n )\n ),\n ( flag(strings)\n -> wst\n ; true\n ),\n forall(\n ( answer(A1, A2, A3),\n nonvar(A1)\n ),\n retract(answer(A1, A2, A3))\n ),\n retractall(implies(_, answer(_, _, _), _)),\n retractall(implies(_, (answer(_, _, _), _), _)),\n retractall(query(_, _)),\n retractall('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(_, _)),\n retractall(cc(_)),\n retractall(brake),\n retractall(prfstep(answer(_, _, _), _, _, _, _, _, _)),\n retractall(lemma(_, _, _, _, _, _)),\n retractall(got_wi(_, _, _, _, _)),\n retractall(wpfx(_)),\n retractall('<http://www.w3.org/2000/10/swap/log#outputString>'(_, _)),\n retractall('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>'(_, _)),\n nb_setval(csv_header, []),\n cnt(mq),\n nb_getval(mq, Cnt),\n ( Cnt mod 10000 =:= 0\n -> garbage_collect_atoms\n ; true\n ),\n statistics(runtime, [_, Ti4]),\n statistics(walltime, [_, Ti5]),\n ( flag(quiet)\n -> true\n ; format(user_error, 'reasoning ~w [msec cputime] ~w [msec walltime]~n', [Ti4, Ti5]),\n flush_output(user_error)\n ),\n nb_getval(output_statements, Oute),\n Outd is Oute-Outb,\n catch(Outs is round(Outd/Ti5*1000), _, Outs = ''),\n ( ( flag(strings)\n ; flag(quiet)\n )\n -> nl\n ; format('#DONE ~3d [sec] mq=~w out=~d out/sec=~w~n~n', [Ti5, Cnt, Outd, Outs])\n ),\n timestamp(Stmp),\n statistics(inferences, Infe),\n Infd is Infe-Infb,\n catch(Infs is round(Infd/Ti5*1000), _, Infs = ''),\n ( flag(quiet)\n -> true\n ; format(user_error, '~w mq=~w out=~d inf=~w sec=~3d out/sec=~w inf/sec=~w~n~n', [Stmp, Cnt, Outd, Infd, Ti5, Outs, Infs]),\n flush_output(user_error)\n ),\n fail\n ),\n told\n ; ( flag(profile)\n -> asserta(pce_profile:pce_show_profile :- fail),\n profiler(_, cputime)\n ; true\n ),\n catch(eam(0), Exc3,\n ( ( Exc3 = halt(0)\n -> true\n ; format(user_error, '** ERROR ** eam ** ~w~n', [Exc3]),\n flush_output(user_error),\n ( Exc3 = inference_fuse(_)\n -> nb_setval(exit_code, 2)\n ; nb_setval(exit_code, 3)\n )\n )\n )\n ),\n ( flag('pass-only-new')\n -> wh,\n forall(\n pass_only_new(Zn),\n ( indent,\n relabel(Zn, Zr),\n wt(Zr),\n ws(Zr),\n write('.'),\n nl,\n cnt(output_statements)\n )\n ),\n nl\n ; true\n ),\n ( flag(profile)\n -> profiler(_, false),\n tell(user_error),\n show_profile([]),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n )\n ; true\n )\n ),\n ( flag(strings)\n -> wst\n ; true\n ),\n nb_getval(tc, TC),\n nb_getval(tp, TP),\n statistics(runtime, [_, T4]),\n statistics(walltime, [_, T5]),\n ( \\+flag('multi-query')\n -> ( flag(quiet)\n -> true\n ; format(user_error, 'reasoning ~w [msec cputime] ~w [msec walltime]~n', [T4, T5]),\n flush_output(user_error)\n )\n ; true\n ),\n nb_getval(input_statements, Inp),\n nb_getval(output_statements, Outp),\n timestamp(Stamp),\n Ent is TC,\n Step is TP,\n statistics(runtime, [Cpu, _]),\n nb_getval(tr, TR),\n Brake is TR,\n ( statistics(inferences, Inf)\n -> true\n ; Inf = ''\n ),\n catch(Speed is round(Inf/Cpu*1000), _, Speed = ''),\n ( ( flag(strings)\n ; flag(quiet)\n )\n -> true\n ; format('#~w in=~d out=~d ent=~d step=~w brake=~w inf=~w sec=~3d inf/sec=~w~n#ENDS~n~n', [Stamp, Inp, Outp, Ent, Step, Brake, Inf, Cpu, Speed])\n ),\n ( flag(quiet)\n -> true\n ; format(user_error, '~w in=~d out=~d ent=~d step=~w brake=~w inf=~w sec=~3d inf/sec=~w~n~n', [Stamp, Inp, Outp, Ent, Step, Brake, Inf, Cpu, Speed]),\n flush_output(user_error)\n ),\n ( flag('rule-histogram')\n -> findall([RTC, RTP, R],\n ( tabl(ETP, tp, Rule),\n nb_getval(ETP, RTP),\n ( tabl(ETC, tc, Rule)\n -> nb_getval(ETC, RTC)\n ; RTC = 0\n ),\n with_output_to(atom(R), wt(Rule))\n ),\n CntRl\n ),\n sort(CntRl, CntRs),\n reverse(CntRs, CntRr),\n format(user_error, '>>> rule histogram TR=~w <<<~n', [TR]),\n forall(\n member(RCnt, CntRr),\n ( ( last(RCnt, '<http://www.w3.org/2000/10/swap/log#implies>'(X, Y)),\n conj_append(X, pstep(_), Z),\n catch(clause(Y, Z), _, fail)\n -> format(user_error, 'TC=~w TP=~w for component ~w~n', RCnt)\n ; format(user_error, 'TC=~w TP=~w for rule ~w~n', RCnt)\n )\n )\n ),\n format(user_error, '~n', []),\n flush_output(user_error)\n ; true\n ).\n\n%\n% command line options\n%\n\nopts([], []) :-\n !.\nopts(['--blogic'|Argus], Args) :-\n !,\n retractall(flag(blogic)),\n assertz(flag(blogic)),\n retractall(flag(nope)),\n assertz(flag(nope)),\n assertz(implies((implies(D, C, _),\n conj_list(D, K),\n conj_list(C, L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, _), L),\n \\+member(answer(_, _, _), L),\n model(Z, R, J),\n findall(M,\n ( member(M, K),\n ( member(M, J)\n ; M =.. [U, _, _],\n pred(U),\n call(M)\n )\n ),\n Q\n ),\n unify(K, Q),\n ( L = [model(_, [case(P, A)], B)]\n -> \\+member(case(P, _), R),\n append(R, [case(P, A)], T),\n append(J, B, I)\n ; T = R,\n append(J, L, I)\n ),\n sort(I, H),\n H \\= J\n ), (modelo(Z, R, J), model(Z, T, H)), '<>')),\n assertz(implies((implies(D, C, _),\n implies('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, D), C, _),\n labelvars(C, 0, _, some),\n findvars(C, V, beta),\n domain(V, true, P),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'(P, C), B, beta(V))\n ), B, '<>')),\n assertz(implies('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(_, G), G, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n makevars(G, H, beta(V)),\n call(H)\n ), false, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, H), L, K),\n conj_list(C, K),\n conj_list(H, M),\n select('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, C), M, _)\n ), '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, C), '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, H), L, K),\n conj_list(C, K),\n domain(V, C, P),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'(P, H), B, beta(V))\n ), B, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, H), L, K),\n dsplit(K, M, J),\n J \\= [],\n conj_list(R, M),\n conj_list(T, J),\n ( H = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, A)\n -> D = A\n ; D = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, H)\n ),\n ( T = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, F)\n -> E = F\n ; E = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, T)\n ),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'((D, R), E), B, beta(V))\n ), B, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(W, H), L, K),\n conj_list(R, K),\n ( H = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, A)\n -> D = A\n ; D = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, H)\n ),\n domain(V, R, P),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'(P, D), B, beta(V))\n ), B, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, _), L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(_, _), L),\n select('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'([], H), L, K),\n conj_list(H, D),\n append(K, D, E),\n conj_list(F, E)\n ), '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, F), '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(_, _), L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, _), L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(_, _), L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onConstructSurface>'(_, _), L),\n dsplit(L, M, J),\n J \\= [],\n conj_list(R, M),\n conj_list(T, J),\n E = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'([], T),\n domain(V, R, P),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'(P, E), B, beta(V))\n ), B, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, H), L, K),\n findall(M,\n ( member(M, K),\n M \\= '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, _)\n ),\n J\n ),\n conj_list(C, J),\n length(K, N),\n length(J, I),\n N > I,\n conj_list(H, Q),\n sort(Q, A),\n domain(V, C, P),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'(P, model(domain(P), [case(C, H)], A)), B, beta(V))\n ), B, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(_, H), L, K),\n conj_list(R, K),\n makevars(':-'(H, R), C, beta(V)),\n copy_term_nat(C, CC),\n labelvars(CC, 0, _, avar),\n ( \\+cc(CC)\n -> assertz(cc(CC)),\n assertz(C)\n ; true\n )), true, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(V, G),\n conj_list(G, L),\n ( select('<http://www.w3.org/2000/10/swap/log#onConstructSurface>'(_, H), L, K)\n -> conj_list(I, K)\n ; I = G,\n H = G\n ),\n djiti_answer(answer(H), J),\n makevars(implies(I, J, '<>'), C, beta(V)),\n copy_term_nat(C, CC),\n labelvars(CC, 0, _, avar),\n ( \\+cc(CC)\n -> assertz(cc(CC)),\n assertz(C),\n retractall(brake)\n ; true\n )), true, '<>')),\n opts(Argus, Args).\nopts(['--csv-separator',Separator|Argus], Args) :-\n !,\n retractall(flag('csv-separator')),\n assertz(flag('csv-separator', Separator)),\n opts(Argus, Args).\nopts(['--debug'|Argus], Args) :-\n !,\n retractall(flag(debug)),\n assertz(flag(debug)),\n opts(Argus, Args).\nopts(['--debug-cnt'|Argus], Args) :-\n !,\n retractall(flag('debug-cnt')),\n assertz(flag('debug-cnt')),\n opts(Argus, Args).\nopts(['--debug-djiti'|Argus], Args) :-\n !,\n retractall(flag('debug-djiti')),\n assertz(flag('debug-djiti')),\n opts(Argus, Args).\nopts(['--debug-implies'|Argus], Args) :-\n !,\n retractall(flag('debug-implies')),\n assertz(flag('debug-implies')),\n opts(Argus, Args).\nopts(['--debug-models'|Argus], Args) :-\n !,\n retractall(flag('debug-models')),\n assertz(flag('debug-models')),\n opts(Argus, Args).\nopts(['--debug-pvm'|Argus], Args) :-\n !,\n retractall(flag('debug-pvm')),\n assertz(flag('debug-pvm')),\n opts(Argus, Args).\nopts(['--help'|_], _) :-\n \\+flag(image, _),\n \\+flag('debug-pvm'),\n !,\n help_info(Help),\n format(user_error, '~w~n', [Help]),\n flush_output(user_error),\n throw(halt(0)).\nopts(['--hmac-key',Key|Argus], Args) :-\n !,\n retractall(flag('hmac-key', _)),\n assertz(flag('hmac-key', Key)),\n opts(Argus, Args).\nopts(['--ignore-inference-fuse'|Argus], Args) :-\n !,\n retractall(flag('ignore-inference-fuse')),\n assertz(flag('ignore-inference-fuse')),\n opts(Argus, Args).\nopts(['--image',File|Argus], Args) :-\n !,\n retractall(flag(image, _)),\n assertz(flag(image, File)),\n opts(Argus, Args).\nopts(['--license'|_], _) :-\n !,\n license_info(License),\n format(user_error, '~w~n', [License]),\n flush_output(user_error),\n throw(halt(0)).\nopts(['--max-inferences',Lim|Argus], Args) :-\n !,\n ( number(Lim)\n -> Limit = Lim\n ; catch(atom_number(Lim, Limit), Exc,\n ( format(user_error, '** ERROR ** max-inferences ** ~w~n', [Exc]),\n flush_output(user_error),\n flush_output,\n throw(halt(1))\n )\n )\n ),\n retractall(flag('max-inferences', _)),\n assertz(flag('max-inferences', Limit)),\n opts(Argus, Args).\nopts(['--multi-query'|Argus], Args) :-\n !,\n retractall(flag('multi-query')),\n assertz(flag('multi-query')),\n opts(Argus, Args).\nopts(['--no-distinct-input'|Argus], Args) :-\n !,\n retractall(flag('no-distinct-input')),\n assertz(flag('no-distinct-input')),\n opts(Argus, Args).\nopts(['--no-distinct-output'|Argus], Args) :-\n !,\n retractall(flag('no-distinct-output')),\n assertz(flag('no-distinct-output')),\n opts(Argus, Args).\nopts(['--no-erase'|Argus], Args) :-\n !,\n retractall(flag('no-erase')),\n assertz(flag('no-erase')),\n opts(Argus, Args).\nopts(['--no-numerals'|Argus], Args) :-\n !,\n retractall(flag('no-numerals')),\n assertz(flag('no-numerals')),\n opts(Argus, Args).\nopts(['--no-qnames'|Argus], Args) :-\n !,\n retractall(flag('no-qnames')),\n assertz(flag('no-qnames')),\n opts(Argus, Args).\nopts(['--no-qvars'|Argus], Args) :-\n !,\n retractall(flag('no-qvars')),\n assertz(flag('no-qvars')),\n opts(Argus, Args).\nopts(['--no-ucall'|Argus], Args) :-\n !,\n retractall(flag('no-ucall')),\n assertz(flag('no-ucall')),\n opts(Argus, Args).\nopts(['--nope'|Argus], Args) :-\n !,\n retractall(flag(nope)),\n assertz(flag(nope)),\n opts(Argus, Args).\nopts(['--output',File|Argus], Args) :-\n !,\n retractall(flag('output', _)),\n open(File, write, Out, [encoding(utf8)]),\n tell(Out),\n assertz(flag('output', Out)),\n opts(Argus, Args).\nopts(['--pass-all-ground'|Argus], Args) :-\n !,\n retractall(flag('pass-all-ground')),\n assertz(flag('pass-all-ground')),\n opts(['--pass-all'|Argus], Args).\nopts(['--pass-only-new'|Argus], Args) :-\n !,\n retractall(flag('pass-only-new')),\n assertz(flag('pass-only-new')),\n opts(Argus, Args).\nopts(['--intermediate',File|Argus], Args) :-\n !,\n retractall(flag(intermediate, _)),\n open(File, write, Out, [encoding(utf8)]),\n assertz(flag(intermediate, Out)),\n opts(Argus, Args).\nopts(['--profile'|Argus], Args) :-\n !,\n retractall(flag(profile)),\n assertz(flag(profile)),\n opts(Argus, Args).\nopts(['--quantify',Prefix|Argus], Args) :-\n !,\n assertz(flag('quantify', Prefix)),\n opts(Argus, Args).\nopts(['--quiet'|Argus], Args) :-\n !,\n retractall(flag(quiet)),\n assertz(flag(quiet)),\n opts(Argus, Args).\nopts(['--random-seed'|Argus], Args) :-\n !,\n N is random(2^120),\n nb_setval(random, N),\n opts(Argus, Args).\nopts(['--restricted'|Argus], Args) :-\n !,\n retractall(flag(restricted)),\n assertz(flag(restricted)),\n opts(Argus, Args).\nopts(['--rule-histogram'|Argus], Args) :-\n !,\n retractall(flag('rule-histogram')),\n assertz(flag('rule-histogram')),\n opts(Argus, Args).\nopts(['--skolem-genid',Genid|Argus], Args) :-\n !,\n retractall(flag('skolem-genid', _)),\n assertz(flag('skolem-genid', Genid)),\n opts(Argus, Args).\nopts(['--statistics'|Argus], Args) :-\n !,\n retractall(flag(statistics)),\n assertz(flag(statistics)),\n opts(Argus, Args).\nopts(['--strings'|Argus], Args) :-\n !,\n retractall(flag(strings)),\n assertz(flag(strings)),\n opts(Argus, Args).\nopts(['--tactic','limited-answer',Lim|Argus], Args) :-\n !,\n ( number(Lim)\n -> Limit = Lim\n ; catch(atom_number(Lim, Limit), Exc,\n ( format(user_error, '** ERROR ** limited-answer ** ~w~n', [Exc]),\n flush_output(user_error),\n flush_output,\n throw(halt(1))\n )\n )\n ),\n retractall(flag('limited-answer', _)),\n assertz(flag('limited-answer', Limit)),\n opts(Argus, Args).\nopts(['--tactic','linear-select'|Argus], Args) :-\n !,\n retractall(flag(tactic, 'linear-select')),\n assertz(flag(tactic, 'linear-select')),\n opts(Argus, Args).\nopts(['--tactic',Tactic|_], _) :-\n !,\n throw(not_supported_tactic(Tactic)).\nopts(['--version'|_], _) :-\n !,\n throw(halt(0)).\nopts(['--warn'|Argus], Args) :-\n !,\n retractall(flag(warn)),\n assertz(flag(warn)),\n opts(Argus, Args).\nopts(['--wcache',Argument,File|Argus], Args) :-\n !,\n absolute_uri(Argument, Arg),\n retractall(wcache(Arg, _)),\n assertz(wcache(Arg, File)),\n opts(Argus, Args).\nopts([Arg|_], _) :-\n \\+memberchk(Arg, ['--entail', '--help', '--n3', '--n3p', '--not-entail', '--pass', '--pass-all', '--proof', '--query', '--turtle']),\n sub_atom(Arg, 0, 2, _, '--'),\n !,\n throw(not_supported_option(Arg)).\nopts([Arg|Argus], [Arg|Args]) :-\n opts(Argus, Args).\n\nargs([]) :-\n !.\nargs(['--entail',Arg|Args]) :-\n !,\n nb_setval(entail_mode, true),\n n3_n3p(Arg, entail),\n nb_setval(entail_mode, false),\n args(Args).\nargs(['--not-entail',Arg|Args]) :-\n !,\n nb_setval(entail_mode, true),\n n3_n3p(Arg, 'not-entail'),\n nb_setval(entail_mode, false),\n args(Args).\nargs(['--n3',Arg|Args]) :-\n !,\n absolute_uri(Arg, A),\n atomic_list_concat(['<', A, '>'], R),\n assertz(scope(R)),\n ( flag(intermediate, Out)\n -> portray_clause(Out, scope(R))\n ; true\n ),\n n3_n3p(Arg, data),\n nb_setval(fdepth, 0),\n nb_setval(pdepth, 0),\n nb_setval(cdepth, 0),\n args(Args).\nargs(['--n3p',Argument|Args]) :-\n !,\n retractall(flag(n3p)),\n assertz(flag(n3p)),\n absolute_uri(Argument, Arg),\n ( wcacher(Arg, File)\n -> ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w FROM ~w ', [Arg, File]),\n flush_output(user_error)\n ),\n open(File, read, In, [encoding(utf8)])\n ; ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w ', [Arg]),\n flush_output(user_error)\n ),\n ( ( sub_atom(Arg, 0, 5, _, 'http:')\n -> true\n ; sub_atom(Arg, 0, 6, _, 'https:')\n )\n -> http_open(Arg, In, []),\n set_stream(In, encoding(utf8))\n ; ( sub_atom(Arg, 0, 5, _, 'file:')\n -> ( parse_url(Arg, Parts)\n -> memberchk(path(File), Parts)\n ; sub_atom(Arg, 7, _, 0, File)\n )\n ; File = Arg\n ),\n ( File = '-'\n -> In = user_input\n ; open(File, read, In, [encoding(utf8)])\n )\n )\n ),\n repeat,\n read_term(In, Rt, []),\n ( Rt = end_of_file\n -> catch(read_term(In, _, []), _, true)\n ; n3pin(Rt, In, File, data),\n fail\n ),\n !,\n ( File = '-'\n -> true\n ; close(In)\n ),\n ( retract(tmpfile(File))\n -> delete_file(File)\n ; true\n ),\n findall(SCnt,\n ( retract(scount(SCnt))\n ),\n SCnts\n ),\n sum(SCnts, SC),\n nb_getval(input_statements, IN),\n Inp is SC+IN,\n nb_setval(input_statements, Inp),\n ( flag(quiet)\n -> true\n ; ( SC =\\= 0\n -> format(user_error, 'SC=~w~n', [SC])\n ; format(user_error, '~n', [])\n ),\n flush_output(user_error)\n ),\n args(Args).\nargs(['--pass'|Args]) :-\n !,\n ( flag(nope),\n \\+flag('limited-answer', _),\n ( flag('no-distinct-input')\n -> flag('no-distinct-output')\n ; true\n ),\n \\+implies(_, answer(_, _, _), _),\n \\+implies(_, (answer(_, _, _), _), _)\n -> assertz(query(exopred(P, S, O), exopred(P, S, O)))\n ; assertz(implies(exopred(P, S, O), answer(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/pass>'))\n ),\n ( flag(intermediate, Out)\n -> portray_clause(Out, implies(exopred(P, S, O), answer(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/pass>'))\n ; true\n ),\n args(Args).\nargs(['--pass-all'|Args]) :-\n !,\n assertz(implies((exopred(P, S, O), \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(P, '<http://www.w3.org/2000/10/swap/log#implies>')),\n answer(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#implies>'(A, C), \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(A, true)),\n answer('<http://www.w3.org/2000/10/swap/log#implies>', A, C), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>')),\n assertz(implies(':-'(C, A),\n answer(':-', C, A), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>')),\n ( flag(intermediate, Out)\n -> portray_clause(Out, implies((exopred(P, S, O), \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(P, '<http://www.w3.org/2000/10/swap/log#implies>')),\n answer(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>')),\n portray_clause(Out, implies(('<http://www.w3.org/2000/10/swap/log#implies>'(A, C), \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(A, true)),\n answer('<http://www.w3.org/2000/10/swap/log#implies>', A, C), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>')),\n portray_clause(Out, implies((':-'(C, A), \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(A, true)),\n answer(':-', C, A), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>'))\n ; true\n ),\n args(Args).\nargs(['--proof',Arg|Args]) :-\n !,\n absolute_uri(Arg, A),\n atomic_list_concat(['<', A, '>'], R),\n assertz(scope(R)),\n ( flag(intermediate, Out)\n -> portray_clause(Out, scope(R))\n ; true\n ),\n n3_n3p(Arg, data),\n ( got_pi\n -> true\n ; assertz(implies(('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'(LEMMA, '<http://www.w3.org/2000/10/swap/reason#Inference>'),\n '<http://www.w3.org/2000/10/swap/reason#gives>'(LEMMA, GRAPH),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphMember>'(GRAPH, exopred(P, S, O))),\n exopred(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/proof-lemma>')),\n assertz(implies(('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'(LEMMA, '<http://www.w3.org/2000/10/swap/reason#Extraction>'),\n '<http://www.w3.org/2000/10/swap/reason#gives>'(LEMMA, GRAPH),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphMember>'(GRAPH, exopred(P, S, O))),\n exopred(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/proof-lemma>')),\n assertz(got_pi)\n ),\n args(Args).\nargs(['--query',Arg|Args]) :-\n !,\n n3_n3p(Arg, query),\n args(Args).\nargs(['--turtle',Argument|Args]) :-\n !,\n absolute_uri(Argument, Arg),\n atomic_list_concat(['<', Arg, '>'], R),\n assertz(scope(R)),\n ( flag(intermediate, Out)\n -> portray_clause(Out, scope(R))\n ; true\n ),\n ( wcacher(Arg, File)\n -> ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w FROM ~w ', [Arg, File]),\n flush_output(user_error)\n ),\n open(File, read, In, [encoding(utf8)])\n ; ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w ', [Arg]),\n flush_output(user_error)\n ),\n ( ( sub_atom(Arg, 0, 5, _, 'http:')\n -> true\n ; sub_atom(Arg, 0, 6, _, 'https:')\n )\n -> http_open(Arg, In, []),\n set_stream(In, encoding(utf8))\n ; ( sub_atom(Arg, 0, 5, _, 'file:')\n -> ( parse_url(Arg, Parts)\n -> memberchk(path(File), Parts)\n ; sub_atom(Arg, 7, _, 0, File)\n )\n ; File = Arg\n ),\n ( File = '-'\n -> In = user_input\n ; open(File, read, In, [encoding(utf8)])\n )\n )\n ),\n retractall(base_uri(_)),\n ( Arg = '-'\n -> absolute_uri('', Abu),\n assertz(base_uri(Abu))\n ; assertz(base_uri(Arg))\n ),\n retractall(ns(_, _)),\n ( Arg = '-'\n -> D = '#'\n ; atomic_list_concat([Arg, '#'], D)\n ),\n assertz(ns('', D)),\n nb_setval(sc, 0),\n rdf_read_turtle(stream(In), Triples, []),\n close(In),\n forall(\n member(rdf(S, P, O), Triples),\n ( ttl_n3p(S, Subject),\n ttl_n3p(P, Predicate),\n ttl_n3p(O, Object),\n Triple =.. [Predicate, Subject, Object],\n djiti_assertz(Triple),\n ( flag(intermediate, Out)\n -> format(Out, '~q.~n', [Triple])\n ; true\n ),\n ( flag(nope)\n -> true\n ; assertz(prfstep(Triple, true, _, Triple, _, forward, R))\n )\n )\n ),\n length(Triples, SC),\n nb_getval(input_statements, IN),\n Inp is SC+IN,\n nb_setval(input_statements, Inp),\n ( flag(quiet)\n -> true\n ; format(user_error, 'SC=~w~n', [SC]),\n flush_output(user_error)\n ),\n args(Args).\nargs([Arg|Args]) :-\n args(['--n3', Arg|Args]).\n\nn3pin(Rt, In, File, Mode) :-\n ( Rt = ':-'(Rg)\n -> ( flag('parse-only')\n -> true\n ; call(Rg)\n ),\n ( flag(intermediate, Out)\n -> format(Out, '~q.~n', [Rt])\n ; true\n )\n ; dynify(Rt),\n ( ( Rt = ':-'(Rh, _)\n -> predicate_property(Rh, dynamic)\n ; predicate_property(Rt, dynamic)\n )\n -> true\n ; ( File = '-'\n -> true\n ; close(In)\n ),\n ( retract(tmpfile(File))\n -> delete_file(File)\n ; true\n ),\n throw(builtin_redefinition(Rt))\n ),\n ( Rt = pfx(Pfx, _)\n -> retractall(pfx(Pfx, _))\n ; true\n ),\n ( Rt = scope(Scope)\n -> nb_setval(current_scope, Scope)\n ; true\n ),\n ( Rt = ':-'(Ci, Px),\n conjify(Px, Pi)\n -> ( Ci = true\n -> ( flag('parse-only')\n -> true\n ; call(Pi)\n )\n ; nb_getval(current_scope, Si),\n copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(Pi, Ci), Ri),\n ( flag(nope)\n -> Ph = Pi\n ; ( Pi = when(Ai, Bi)\n -> conj_append(Bi, istep(Si, Pi, Ci, Ri), Bh),\n Ph = when(Ai, Bh)\n ; conj_append(Pi, istep(Si, Pi, Ci, Ri), Ph)\n )\n ),\n ( flag('rule-histogram')\n -> ( Ph = when(Ak, Bk)\n -> conj_append(Bk, pstep(Ri), Bj),\n Pj = when(Ak, Bj)\n ; conj_append(Ph, pstep(Ri), Pj)\n )\n ; Pj = Ph\n ),\n functor(Ci, CPi, _),\n ( flag(intermediate, Out)\n -> ( \\+cpred(CPi)\n -> portray_clause(Out, cpred(CPi))\n ; true\n ),\n portray_clause(Out, ':-'(Ci, Pi))\n ; true\n ),\n ( \\+cpred(CPi)\n -> assertz(cpred(CPi))\n ; true\n ),\n assertz(':-'(Ci, Pj))\n )\n ; ( Rt \\= implies(_, _, _),\n Rt \\= scount(_),\n \\+flag('no-distinct-input'),\n call(Rt)\n -> true\n ; ( Rt \\= pred('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>'),\n \\+ (Rt = scope(_), Mode = query)\n -> djiti_assertz(Rt),\n ( flag(intermediate, Out),\n Rt \\= scount(_)\n -> format(Out, '~q.~n', [Rt])\n ; true\n ),\n ( Rt \\= flag(_, _),\n Rt \\= scope(_),\n Rt \\= pfx(_, _),\n Rt \\= pred(_),\n Rt \\= cpred(_),\n Rt \\= scount(_)\n -> ( flag(nope)\n -> true\n ; term_index(true, Pnd),\n nb_getval(current_scope, Src),\n assertz(prfstep(Rt, true, Pnd, Rt, _, forward, Src))\n )\n ; true\n )\n ; true\n )\n )\n )\n ).\n\n% N3 to N3P compiler\n\nn3_n3p(Argument, Mode) :-\n absolute_uri(Argument, Arg),\n tmp_file(Tmp),\n ( wcacher(Arg, File)\n -> ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w FROM ~w ', [Arg, File]),\n flush_output(user_error)\n ),\n open(File, read, In, [encoding(utf8)])\n ; ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w ', [Arg]),\n flush_output(user_error)\n ),\n ( ( sub_atom(Arg, 0, 5, _, 'http:')\n -> true\n ; sub_atom(Arg, 0, 6, _, 'https:')\n )\n -> http_open(Arg, In, []),\n set_stream(In, encoding(utf8))\n ; ( sub_atom(Arg, 0, 5, _, 'file:')\n -> ( parse_url(Arg, Parts)\n -> memberchk(path(File), Parts)\n ; sub_atom(Arg, 7, _, 0, File)\n )\n ; File = Arg\n ),\n ( File = '-'\n -> In = user_input\n ; open(File, read, In, [encoding(utf8)])\n )\n )\n ),\n retractall(base_uri(_)),\n ( Arg = '-'\n -> absolute_uri('', Abu),\n assertz(base_uri(Abu))\n ; assertz(base_uri(Arg))\n ),\n retractall(ns(_, _)),\n ( Arg = '-'\n -> D = '#'\n ; atomic_list_concat([Arg, '#'], D)\n ),\n assertz(ns('', D)),\n retractall(quvar(_, _, _)),\n retractall(qevar(_, _, _)),\n retractall(evar(_, _, _)),\n nb_setval(line_number, 1),\n nb_setval(sc, 0),\n nb_setval(semantics, []),\n atomic_list_concat(['\\'<', Arg, '>\\''], Src),\n atomic_list_concat([Tmp, '_p'], Tmp_p),\n assertz(tmpfile(Tmp_p)),\n open(Tmp_p, write, Ws, [encoding(utf8)]),\n tell(Ws),\n catch(\n ( repeat,\n tokens(In, Tokens),\n phrase(document(Triples), Tokens, Rest),\n ( Rest = []\n -> true\n ; nb_getval(line_number, Ln),\n throw(invalid_document(after_line(Ln)))\n ),\n ( Mode = semantics\n -> nb_getval(semantics, TriplesPrev),\n append(TriplesPrev, Triples, TriplesNext),\n findall(Tr,\n ( member(Triple, TriplesNext),\n ( Triple = ':-'(Head, Body)\n -> Tr = '\\'<http://www.w3.org/2000/10/swap/log#implies>\\''(Body, Head)\n ; Tr = Triple\n )\n ),\n TriplesNext2\n ),\n nb_setval(semantics, TriplesNext2)\n ; tr_n3p(Triples, Src, Mode)\n ),\n Tokens = []\n ),\n Exc2,\n ( ( Mode = semantics\n -> told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n throw(Exc2)\n ; true\n ),\n ( wcacher(Arg, File)\n -> format(user_error, '** ERROR ** ~w FROM ~w ** ~w~n', [Arg, File, Exc2])\n ; format(user_error, '** ERROR ** ~w ** ~w~n', [Arg, Exc2])\n ),\n flush_output(user_error),\n nb_setval(exit_code, 1),\n ( ( \\+data_fuse,\n Mode == 'not-entail'\n ; data_fuse,\n Mode == entail\n )\n -> write(query(true, true)),\n writeln('.')\n ; true\n ),\n assertz(data_fuse)\n )\n ),\n ( Mode = semantics\n -> nb_getval(semantics, List),\n write(semantics(Src, List)),\n writeln('.')\n ; true\n ),\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n ( File = '-'\n -> true\n ; close(In)\n ),\n ( retract(tmpfile(Tmp))\n -> delete_file(Tmp)\n ; true\n ),\n ( flag(intermediate, Out)\n -> forall(\n ( pfx(Pp, Pu),\n \\+wpfx(Pp)\n ),\n ( portray_clause(Out, pfx(Pp, Pu)),\n assertz(wpfx(Pp))\n )\n )\n ; true\n ),\n open(Tmp_p, read, Rs, [encoding(utf8)]),\n ( Mode = semantics\n -> repeat,\n read(Rs, Rt),\n ( Rt = end_of_file\n -> true\n ; djiti_assertz(Rt),\n ( Rt = semantics(_, L)\n -> length(L, N),\n nb_setval(sc, N)\n ; Rt \\= semantics(_, []),\n nb_setval(sc, 1)\n ),\n fail\n )\n ; repeat,\n read(Rs, Rt),\n ( Rt = end_of_file\n -> true\n ; dynify(Rt),\n ( ground(Rt),\n Rt \\= ':-'(_, _)\n -> ( predicate_property(Rt, dynamic)\n -> true\n ; close(Rs),\n ( retract(tmpfile(Tmp_p))\n -> delete_file(Tmp_p)\n ; true\n ),\n throw(builtin_redefinition(Rt))\n ),\n ( Rt \\= implies(_, _, _),\n \\+flag('no-distinct-input'),\n call(Rt)\n -> true\n ; djiti_assertz(Rt),\n cnt(sc),\n ( flag(intermediate, Out)\n -> portray_clause(Out, Rt)\n ; true\n )\n )\n ; ( Rt = prfstep(Ct, Pt, _, Qt, It, Mt, St)\n -> term_index(Pt, Pnd),\n ( nonvar(It)\n -> copy_term_nat(It, Ic)\n ; Ic = It\n ),\n ( \\+prfstep(Ct, Pt, Pnd, Qt, Ic, Mt, St)\n -> assertz(prfstep(Ct, Pt, Pnd, Qt, Ic, Mt, St))\n ; true\n )\n ; ( Rt = ':-'(Ci, Px),\n ( Px = true\n -> functor(Ci, Cf, _),\n ( \\+pred(Cf),\n \\+cpred(Cf)\n -> assertz(pred(Cf))\n ; true\n )\n ; true\n ),\n conjify(Px, Pi)\n -> ( Ci = true\n -> ( flag(intermediate, Out)\n -> portray_clause(Out, ':-'(Pi))\n ; true\n ),\n ( flag('parse-only')\n -> true\n ; call(Pi)\n )\n ; atomic_list_concat(['<', Arg, '>'], Si),\n copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(Pi, Ci), Ri),\n ( flag(nope)\n -> Ph = Pi\n ; ( Pi = when(Ai, Bi)\n -> conj_append(Bi, istep(Si, Pi, Ci, Ri), Bh),\n Ph = when(Ai, Bh)\n ; conj_append(Pi, istep(Si, Pi, Ci, Ri), Ph)\n )\n ),\n ( flag('rule-histogram')\n -> ( Ph = when(Ak, Bk)\n -> conj_append(Bk, pstep(Ri), Bj),\n Pj = when(Ak, Bj)\n ; conj_append(Ph, pstep(Ri), Pj)\n )\n ; Pj = Ph\n ),\n cnt(sc),\n functor(Ci, CPi, _),\n ( flag(intermediate, Out)\n -> ( \\+cpred(CPi)\n -> portray_clause(Out, cpred(CPi))\n ; true\n ),\n portray_clause(Out, ':-'(Ci, Pi))\n ; true\n ),\n ( \\+cpred(CPi)\n -> assertz(cpred(CPi))\n ; true\n ),\n assertz(':-'(Ci, Pj))\n )\n ; djiti_assertz(Rt),\n cnt(sc),\n ( flag(intermediate, Out)\n -> portray_clause(Out, Rt)\n ; true\n )\n )\n )\n ),\n fail\n )\n ),\n close(Rs),\n ( retract(tmpfile(Tmp_p))\n -> delete_file(Tmp_p)\n ; true\n ),\n nb_getval(sc, SC),\n nb_getval(input_statements, IN),\n Inp is SC+IN,\n nb_setval(input_statements, Inp),\n ( flag(quiet)\n -> true\n ; format(user_error, 'SC=~w~n', [SC]),\n flush_output(user_error)\n ),\n !.\n\ntr_n3p([], _, _) :-\n !.\ntr_n3p(X, _, entail) :-\n !,\n conj_list(Y, X),\n write(query(Y, true)),\n writeln('.').\ntr_n3p(X, _, 'not-entail') :-\n !,\n conj_list(Y, X),\n write(query(\\+Y, true)),\n writeln('.').\ntr_n3p(['\\'<http://www.w3.org/2000/10/swap/log#implies>\\''(X, Y)|Z], Src, query) :-\n !,\n ( Y = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, T)\n -> ( is_list(T)\n -> H = T\n ; findvars(X, U, epsilon),\n distinct(U, H)\n ),\n nb_setval(csv_header, H),\n V = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, H)\n ; V = Y\n ),\n ( \\+flag('limited-answer', _),\n flag(nope),\n ( flag('no-distinct-output')\n ; V = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, _)\n )\n -> write(query(X, V)),\n writeln('.')\n ; djiti_answer(answer(V), A),\n write(implies(X, A, Src)),\n writeln('.')\n ),\n tr_n3p(Z, Src, query).\ntr_n3p([':-'(Y, X)|Z], Src, query) :-\n !,\n ( Y = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, T)\n -> ( is_list(T)\n -> H = T\n ; findvars(X, U, epsilon),\n distinct(U, H)\n ),\n nb_setval(csv_header, H),\n V = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, H)\n ; V = Y\n ),\n ( ( \\+flag('limited-answer', _)\n ; V = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, _),\n flag(strings)\n ),\n flag(nope)\n -> write(query(X, V)),\n writeln('.')\n ; djiti_answer(answer(V), A),\n write(implies(X, A, Src)),\n writeln('.')\n ),\n tr_n3p(Z, Src, query).\ntr_n3p(['\\'<http://www.w3.org/2000/10/swap/log#implies>\\''(X, Y)|Z], Src, Mode) :-\n !,\n ( flag(tactic, 'linear-select')\n -> write(implies(X, '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>\\''(X, Y), Src)),\n writeln('.'),\n write(implies('\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>\\''(X, Y), Y, Src)),\n writeln('.')\n ; write(implies(X, Y, Src)),\n writeln('.')\n ),\n tr_n3p(Z, Src, Mode).\ntr_n3p([':-'(Y, X)|Z], Src, Mode) :-\n !,\n tr_tr(Y, U),\n write(':-'(U, X)),\n writeln('.'),\n tr_n3p(Z, Src, Mode).\ntr_n3p(['\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tactic>\\''(X, Y)|Z], Src, Mode) :-\n !,\n write('\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tactic>\\''(X, Y)),\n writeln('.'),\n tr_n3p(Z, Src, Mode).\ntr_n3p([X|Z], Src, Mode) :-\n ( X \\= '\\'<http://www.w3.org/2000/10/swap/reason#gives>\\''(_, _)\n -> tr_tr(X, Y)\n ; Y = X\n ),\n ( findvars(Y, U, epsilon),\n U = []\n -> write(Y),\n writeln('.'),\n ( flag(nope)\n -> true\n ; write(prfstep(Y, true, _, Y, _, forward, Src)),\n writeln('.')\n )\n ; write(':-'(Y, true)),\n writeln('.')\n ),\n tr_n3p(Z, Src, Mode).\n\ntr_tr([], []) :-\n !.\ntr_tr([A|B], [C|D]) :-\n !,\n tr_tr(A, C),\n tr_tr(B, D).\ntr_tr(A, B) :-\n atom(A),\n !,\n ( atom_concat('_', C, A),\n ( sub_atom(C, 0, _, _, 'bn_')\n ; sub_atom(C, 0, _, _, 'e_')\n )\n -> nb_getval(var_ns, Sns),\n atomic_list_concat(['\\'<', Sns, C, '>\\''], B)\n ; B = A\n ).\ntr_tr(A, A) :-\n number(A),\n !.\ntr_tr(A, B) :-\n A =.. [C|D],\n tr_tr(D, E),\n B =.. [C|E].\n\ntr_split([], [], []) :-\n !.\ntr_split([A|B], C, [A|D]) :-\n functor(A, '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>\\'', _),\n !,\n tr_split(B, C, D).\ntr_split([A|B], C, D) :-\n functor(A, '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#true>\\'', _),\n !,\n tr_split(B, C, D).\ntr_split([A|B], [A|C], D) :-\n tr_split(B, C, D).\n\nttl_n3p(literal(type(A, B)), literal(B, type(A))) :-\n !.\nttl_n3p(literal(lang(A, B)), literal(B, lang(A))) :-\n !.\nttl_n3p(literal(A), literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n !.\nttl_n3p(node(A), B) :-\n !,\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'node_', A, '>'], B).\nttl_n3p(A, B) :-\n atomic_list_concat(['<', A, '>'], B).\n\n%\n% N3 parser\n%\n% according to http://www.w3.org/2000/10/swap/grammar/n3-ietf.txt\n% inspired by http://code.google.com/p/km-rdf/wiki/Henry\n%\n\nannotation(Triple, Triples) -->\n [lb_pipe],\n !,\n propertylist(Triple, Triples),\n { ( Triples \\= []\n -> true\n ; nb_getval(line_number, Ln),\n throw('empty_triple_annotation'(after_line(Ln)))\n )\n },\n [pipe_rb].\nannotation(_, []) -->\n [].\n\nbarename(BareName) -->\n [name(BareName)].\n\nbarename_csl([BareName|Tail]) -->\n barename(BareName),\n !,\n barename_csl_tail(Tail).\nbarename_csl([]) -->\n [].\n\nbarename_csl_tail([BareName|Tail]) -->\n [','],\n !,\n barename(BareName),\n barename_csl_tail(Tail).\nbarename_csl_tail([]) -->\n [].\n\nboolean(true) -->\n [name('true')],\n !.\nboolean(false) -->\n [name('false')],\n !.\nboolean(Boolean) -->\n literal(Atom, type(T)),\n { T = '\\'<http://www.w3.org/2001/XMLSchema#boolean>\\'',\n ( memberchk([Boolean, Atom], [[true, '\\'true\\''], [true, true], [true, '\\'1\\''], [false, '\\'false\\''], [false, false], [false, '\\'0\\'']])\n -> true\n ; ( flag('parse-only')\n -> true\n ; nb_getval(line_number, Ln),\n throw(invalid_boolean_literal(Atom, after_line(Ln)))\n )\n )\n }.\n\ndeclaration -->\n [atname(base)],\n !,\n explicituri(U),\n { base_uri(V),\n resolve_uri(U, V, URI),\n retractall(base_uri(_)),\n assertz(base_uri(URI))\n }.\ndeclaration -->\n [name(Name)],\n { downcase_atom(Name, 'base')\n },\n !,\n explicituri(U),\n { base_uri(V),\n resolve_uri(U, V, URI),\n retractall(base_uri(_)),\n assertz(base_uri(URI))\n },\n withoutdot.\ndeclaration -->\n [atname(prefix)],\n !,\n prefix(Prefix),\n explicituri(U),\n { base_uri(V),\n resolve_uri(U, V, URI),\n retractall(ns(Prefix, _)),\n assertz(ns(Prefix, URI)),\n put_pfx(Prefix, URI)\n }.\ndeclaration -->\n [name(Name)],\n { downcase_atom(Name, 'prefix')\n },\n prefix(Prefix),\n explicituri(U),\n { base_uri(V),\n resolve_uri(U, V, URI),\n retractall(ns(Prefix, _)),\n assertz(ns(Prefix, URI)),\n put_pfx(Prefix, URI)\n },\n withoutdot.\n\ndocument(Triples) -->\n statements_optional(Triples).\n\ndtlang(lang(Langcode)) -->\n [atname(Name)],\n { Name \\= 'is',\n Name \\= 'has'\n },\n !,\n { downcase_atom(Name, N),\n atomic_list_concat(['\\'', N, '\\''], Langcode)\n }.\ndtlang(type(Datatype)) -->\n [caret_caret],\n !,\n uri(Datatype).\ndtlang(type(T)) -->\n { T = '\\'<http://www.w3.org/2001/XMLSchema#string>\\''\n },\n [].\n\nexistential -->\n [atname(forSome)],\n !,\n symbol_csl(Symbols),\n { nb_getval(fdepth, D),\n forall(\n member(S, Symbols),\n ( gensym('qe_', Q),\n asserta(qevar(S, Q, D))\n )\n )\n }.\n\nexplicituri(ExplicitURI) -->\n [relative_uri(ExplicitURI)].\n\nexpression(Node, T) -->\n pathitem(N1, T1),\n pathtail(N1, Node, T2),\n { append(T1, T2, T)\n }.\n\nformulacontent(Formula) -->\n statementlist(List),\n { conj_list(Formula, List)\n }.\n\nliteral(Atom, DtLang) -->\n string(Codes),\n dtlang(DtLang),\n { escape_string(Codes, B),\n escape_string(B, C),\n atom_codes(A, C),\n ( sub_atom(A, _, 1, _, '\\'')\n -> escape_squote(C, D),\n atom_codes(E, D)\n ; E = A\n ),\n atomic_list_concat(['\\'', E, '\\''], Atom)\n }.\n\nnumericliteral(Number) -->\n [numeric(_, NumB)],\n { numeral(NumB, NumC),\n number_codes(Number, NumC)\n }.\n\nobject(Node, Triples) -->\n expression(Node, Triples).\n\nobjecttail(Subject, Verb, [Triple|Triples]) -->\n [','],\n !,\n object(Object, Triples1),\n { ( Verb = isof(Vrb)\n -> Trpl = triple(Object, Vrb, Subject)\n ; Trpl = triple(Subject, Verb, Object)\n )\n },\n annotation(Trpl, Triples2),\n objecttail(Subject, Verb, Triples3),\n { append([Triples1, Triples2, Triples3], Triples),\n ( Verb = isof(V)\n -> ( atom(V),\n \\+sub_atom(V, 0, 1, _, '_')\n -> Triple =.. [V, Object, Subject]\n ; Triple = exopred(V, Object, Subject)\n )\n ; ( atom(Verb),\n \\+sub_atom(Verb, 0, 1, _, '_')\n -> Triple =.. [Verb, Subject, Object]\n ; Triple = exopred(Verb, Subject, Object)\n )\n )\n }.\nobjecttail(_, _, []) -->\n [].\n\npathitem(Name, []) -->\n symbol(S),\n !,\n { ( qevar(S, N, D),\n \\+quvar(S, _, _)\n -> ( D = 1,\n nb_getval(fdepth, FD),\n FD >= D,\n \\+flag('pass-all-ground')\n -> atom_concat('_', N, Name)\n ; atomic_list_concat(['\\'<http://eyereasoner.github.io/var#', N, '>\\''], Name),\n ( pfx('var:', _)\n -> true\n ; assertz(pfx('var:', '<http://eyereasoner.github.io/var#>'))\n )\n )\n ; ( quvar(S, N, D)\n -> ( nb_getval(fdepth, FD),\n FD >= D,\n \\+flag('pass-all-ground')\n -> atom_concat('_', N, Name)\n ; atomic_list_concat(['\\'<http://eyereasoner.github.io/var#', N, '>\\''], Name),\n ( pfx('var:', _)\n -> true\n ; assertz(pfx('var:', '<http://eyereasoner.github.io/var#>'))\n )\n )\n ; Name = S\n )\n )\n }.\npathitem(VarID, []) -->\n [uvar(Var)],\n !,\n { atom_codes(Var, VarCodes),\n subst([[[0'-], [0'_, 0'M, 0'I, 0'N, 0'U, 0'S, 0'_]], [[0'.], [0'_, 0'D, 0'O, 0'T, 0'_]]], VarCodes, VarTidy),\n atom_codes(VarAtom, [0'_|VarTidy]),\n ( flag('pass-all-ground')\n -> nb_getval(var_ns, Sns),\n atom_codes(VarFrag, VarTidy),\n atomic_list_concat(['\\'<', Sns, VarFrag, '>\\''], VarID)\n ; VarID = VarAtom\n )\n }.\npathitem(Number, []) -->\n numericliteral(Number),\n !.\npathitem(Boolean, []) -->\n boolean(Boolean),\n !.\npathitem(Atom, []) -->\n literal(A, type(T)),\n { T = '\\'<http://eulersharp.sourceforge.net/2003/03swap/prolog#atom>\\''\n },\n !,\n { atom_codes(A, B),\n escape_string(C, B),\n atom_codes(Atom, C)\n }.\npathitem(Number, [], L1, L2) :-\n literal(Atom, type(Type), L1, L2),\n nb_getval(fdepth, 0),\n memberchk(Type, ['\\'<http://www.w3.org/2001/XMLSchema#integer>\\'', '\\'<http://www.w3.org/2001/XMLSchema#long>\\'', '\\'<http://www.w3.org/2001/XMLSchema#decimal>\\'', '\\'<http://www.w3.org/2001/XMLSchema#double>\\'']),\n sub_atom(Atom, 1, _, 1, A),\n atom_codes(A, NumB),\n numeral(NumB, NumC),\n number_codes(Number, NumC),\n !.\npathitem(literal(Atom, DtLang), []) -->\n literal(Atom, DtLang),\n !.\npathitem(Subject, Triples) -->\n ['[',name(id)],\n !,\n expression(Subject, T1),\n propertylist(Subject, T2),\n { append(T1, T2, Triples)\n },\n [']'].\npathitem(Node, Triples) -->\n ['['],\n !,\n { gensym('bn_', S),\n ( ( nb_getval(entail_mode, false),\n nb_getval(fdepth, 0)\n ; flag('pass-all-ground')\n )\n -> nb_getval(var_ns, Sns),\n atomic_list_concat(['\\'<', Sns, S, '>\\''], BN)\n ; atom_concat('_', S, BN)\n )\n },\n propertylist(BN, T),\n { ( memberchk('\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>\\''(X, Head), T),\n memberchk('\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>\\''(X, Tail), T),\n del(T, '\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>\\''(X, '\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#List>\\''), U),\n del(U, '\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>\\''(X, Head), V),\n del(V, '\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>\\''(X, Tail), W)\n -> Node = [Head|Tail],\n Triples = W\n ; Node = BN,\n Triples = T\n )\n },\n [']'].\npathitem(set(Distinct), Triples) -->\n ['(', '$'],\n !,\n pathlist(List, Triples),\n { sort(List, Distinct)\n },\n ['$', ')'].\npathitem(List, Triples) -->\n ['('],\n !,\n pathlist(List, Triples),\n [')'].\npathitem(triple(S, P, O), []) -->\n [lt_lt],\n !,\n subject(S, []),\n verb(P, []),\n object(O, []),\n [gt_gt].\npathitem(Node, []) -->\n ['{'],\n { nb_getval(fdepth, I),\n J is I+1,\n nb_setval(fdepth, J)\n },\n formulacontent(Node),\n { retractall(quvar(_, _, J)),\n retractall(qevar(_, _, J)),\n retractall(evar(_, _, J)),\n nb_setval(fdepth, I),\n ( nb_getval(entail_mode, true)\n -> nb_getval(line_number, Ln),\n throw(non_rdf_entailment(Node, after_line(Ln)))\n ; true\n )\n },\n ['}'].\n\npathlist([Node|Rest], Triples) -->\n expression(Node, T),\n !,\n pathlist(Rest, Tail),\n { append(T, Tail, Triples)\n }.\npathlist([], []) -->\n [].\n\npathtail(Node, PNode, [Triple|Triples]) -->\n ['!'],\n !,\n pathitem(Item, Triples2),\n { prolog_verb(Item, Verb),\n gensym('bn_', S),\n ( ( nb_getval(fdepth, 0)\n ; flag('pass-all-ground')\n )\n -> nb_getval(var_ns, Sns),\n atomic_list_concat(['\\'<', Sns, S, '>\\''], BNode)\n ; atom_concat('_', S, BNode)\n ),\n ( Verb = isof(V)\n -> ( atom(V),\n \\+sub_atom(V, 0, 1, _, '_')\n -> Triple =.. [V, BNode, Node]\n ; Triple = exopred(V, BNode, Node)\n )\n ; ( Verb = prolog:Pred\n -> ( BNode = true\n -> Triple =.. [Pred|Node]\n ; ( BNode = false\n -> T =.. [Pred|Node],\n Triple = \\+(T)\n ; ( prolog_sym(_, Pred, func)\n -> T =.. [Pred|Node],\n Triple = is(BNode, T)\n ; Triple =.. [Pred, Node, BNode]\n )\n )\n )\n ; ( atom(Verb),\n \\+sub_atom(Verb, 0, 1, _, '_')\n -> Triple =.. [Verb, Node, BNode]\n ; Triple = exopred(Verb, Node, BNode)\n )\n )\n )\n },\n pathtail(BNode, PNode, Tail),\n { append(Triples2, Tail, Triples)\n }.\npathtail(Node, PNode, [Triple|Triples]) -->\n ['^'],\n !,\n pathitem(Item, Triples2),\n { prolog_verb(Item, Verb),\n gensym('bn_', S),\n ( ( nb_getval(fdepth, 0)\n ; flag('pass-all-ground')\n )\n -> nb_getval(var_ns, Sns),\n atomic_list_concat(['\\'<', Sns, S, '>\\''], BNode)\n ; atom_concat('_', S, BNode)\n ),\n ( Verb = isof(V)\n -> ( atom(V),\n \\+sub_atom(V, 0, 1, _, '_')\n -> Triple =.. [V, Node, BNode]\n ; Triple = exopred(V, Node, BNode)\n )\n ; ( Verb = prolog:Pred\n -> ( Node = true\n -> Triple =.. [Pred|BNode]\n ; ( Node = false\n -> T =.. [Pred|BNode],\n Triple = \\+(T)\n ; ( prolog_sym(_, Pred, func)\n -> T =.. [Pred|BNode],\n Triple = is(Node, T)\n ; Triple =.. [Pred, BNode, Node]\n )\n )\n )\n ; ( atom(Verb),\n \\+sub_atom(Verb, 0, 1, _, '_')\n -> Triple =.. [Verb, BNode, Node]\n ; Triple = exopred(Verb, BNode, Node)\n )\n )\n )\n },\n pathtail(BNode, PNode, Tail),\n { append(Triples2, Tail, Triples)\n }.\npathtail(Node, Node, []) -->\n [].\n\nprefix(Prefix) -->\n [Prefix:''].\n\npropertylist(Subject, [Triple|Triples]) -->\n verb(Item, Triples1),\n { prolog_verb(Item, Verb),\n ( Verb = '\\'<http://www.w3.org/2000/10/swap/log#implies>\\''\n -> nb_setval(mconc, true)\n ; true\n )\n },\n !,\n object(Object, Triples2),\n { ( Verb = isof(Vrb)\n -> Trpl = triple(Object, Vrb, Subject)\n ; Trpl = triple(Subject, Verb, Object)\n ),\n ( Verb = '\\'<http://www.w3.org/2000/10/swap/log#implies>\\''\n -> nb_setval(mconc, false)\n ; true\n )\n },\n annotation(Trpl, Triples3),\n objecttail(Subject, Verb, Triples4),\n propertylisttail(Subject, Triples5),\n { append([Triples1, Triples2, Triples3, Triples4, Triples5], Triples),\n ( Verb = isof(V)\n -> ( atom(V),\n \\+sub_atom(V, 0, 1, _, '_')\n -> Triple =.. [V, Object, Subject]\n ; Triple = exopred(V, Object, Subject)\n )\n ; ( Verb = prolog:Pred\n -> ( Object = true\n -> Triple =.. [Pred|Subject]\n ; ( Object = false\n -> T =.. [Pred|Subject],\n Triple = \\+(T)\n ; ( prolog_sym(_, Pred, func)\n -> T =.. [Pred|Subject],\n Triple = is(Object, T)\n ; Triple =.. [Pred, Subject, Object]\n )\n )\n )\n ; ( atom(Verb),\n \\+sub_atom(Verb, 0, 1, _, '_')\n -> Triple =.. [Verb, Subject, Object]\n ; Triple = exopred(Verb, Subject, Object)\n )\n )\n )\n }.\npropertylist(_, []) -->\n [].\n\npropertylisttail(Subject, Triples) -->\n [';'],\n !,\n propertylisttailsemis,\n propertylist(Subject, Triples).\npropertylisttail(_, []) -->\n [].\n\npropertylisttailsemis -->\n [';'],\n !,\n propertylisttailsemis.\npropertylisttailsemis -->\n [].\n\nqname(URI) -->\n [NS:Name],\n { ( ns(NS, Base)\n -> atomic_list_concat([Base, Name], Name1),\n ( sub_atom(Name1, _, 1, _, '\\'')\n -> atom_codes(Name1, Codes1),\n escape_squote(Codes1, Codes2),\n atom_codes(Name2, Codes2)\n ; Name2 = Name1\n ),\n atomic_list_concat(['\\'<', Name2, '>\\''], URI)\n ; nb_getval(line_number, Ln),\n throw(no_prefix_directive(NS, after_line(Ln)))\n )\n },\n !.\n\nsimpleStatement(Triples) -->\n subject(Subject, Triples1),\n ( { Subject = (D1;D2)\n }\n -> { Triples = [(D1;D2)]\n }\n ; propertylist(Subject, Triples2),\n { append(Triples1, Triples2, Triples)\n }\n ).\n\nstatement([]) -->\n declaration,\n !.\nstatement([]) -->\n universal,\n !.\nstatement([]) -->\n existential,\n !.\nstatement(Statement) -->\n simpleStatement(Statement).\n\nstatementlist(Triples) -->\n statement(Tr),\n !,\n statementtail(T),\n { append(Tr, T, Triples)\n }.\nstatementlist([]) -->\n [].\n\nstatements_optional(Triples) -->\n statement(Tr),\n [dot(Ln)],\n !,\n { nb_setval(line_number, Ln)\n },\n statements_optional(T),\n { append(Tr, T, Triples)\n }.\nstatements_optional([]) -->\n [].\n\nstatementtail(T) -->\n [dot(Ln)],\n !,\n { nb_setval(line_number, Ln)\n },\n statementlist(T).\nstatementtail([]) -->\n [].\n\nstring(Codes) -->\n [literal(Codes)].\n\nsubject(Node, Triples) -->\n expression(Node, Triples).\n\nsymbol(Name) -->\n uri(Name),\n !.\nsymbol(Name) -->\n [name(N)],\n !,\n { ( memberchk(N, [true, false])\n -> Name = N\n ; nb_getval(line_number, Ln),\n throw(invalid_keyword(N, after_line(Ln)))\n )\n }.\nsymbol(Name) -->\n [bnode(Lb)],\n { ( nb_getval(mconc, true)\n -> atom_concat(Lb, '_c', Label)\n ; Label = Lb\n ),\n ( evar(Label, S, 0)\n -> true\n ; atom_concat(Label, '_', M),\n gensym(M, S),\n assertz(evar(Label, S, 0))\n ),\n ( ( nb_getval(entail_mode, false),\n nb_getval(fdepth, 0)\n ; flag('pass-all-ground')\n )\n -> nb_getval(var_ns, Sns),\n ( flag('pass-all-ground')\n -> atomic_list_concat(['\\'<', Sns, Label, '>\\''], Name)\n ; atomic_list_concat(['\\'<', Sns, 'e_', S, '>\\''], Name)\n )\n ; atom_concat('_e_', S, Name)\n )\n }.\n\nsymbol_csl([Symbol|Tail]) -->\n symbol(Symbol),\n !,\n symbol_csl_tail(Tail).\nsymbol_csl([]) -->\n [].\n\nsymbol_csl_tail([Symbol|T]) -->\n [','],\n !,\n symbol(Symbol),\n symbol_csl_tail(T).\nsymbol_csl_tail([]) -->\n [].\n\nuniversal -->\n [atname(forAll)],\n !,\n symbol_csl(Symbols),\n { nb_getval(fdepth, D),\n forall(\n member(S, Symbols),\n ( gensym('qu_', Q),\n asserta(quvar(S, Q, D))\n )\n )\n }.\n\nuri(Name) -->\n explicituri(U),\n !,\n { base_uri(V),\n resolve_uri(U, V, W),\n ( sub_atom(W, _, 1, _, '\\'')\n -> atom_codes(W, X),\n escape_squote(X, Y),\n atom_codes(Z, Y)\n ; Z = W\n ),\n atomic_list_concat(['\\'<', Z, '>\\''], Name)\n }.\nuri(Name) -->\n qname(Name).\n\nverb('\\'<http://www.w3.org/2000/10/swap/log#implies>\\'', []) -->\n ['=', '>'],\n !.\nverb('\\'<http://www.w3.org/2002/07/owl#sameAs>\\'', []) -->\n ['='],\n !.\nverb(':-', []) -->\n [lt_eq],\n !.\nverb('\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>\\'', []) -->\n [name(a)],\n !.\nverb(Node, Triples) -->\n [name(has)],\n !,\n expression(Node, Triples).\nverb(isof(Node), Triples) -->\n [name(is)],\n !,\n expression(Node, Triples),\n [name(of)].\nverb(isof(Node), Triples) -->\n [lt_dash],\n !,\n expression(Node, Triples).\nverb(Node, Triples) -->\n expression(Node, Triples).\n\nwithoutdot, [dot(Ln)] -->\n [dot(Ln)],\n !,\n { throw(unexpected_dot(after_line(Ln)))\n }.\nwithoutdot, [dot(Ln)] -->\n [],\n { nb_getval(line_number, Ln)\n }.\n\n%\n% N3 tokenizer\n%\n\ntokens(In, List) :-\n get_code(In, C0),\n ( token(C0, In, C1, Tok1)\n -> true\n ; nb_getval(line_number, Ln),\n char_code(Char, C0),\n throw(illegal_token(char_code(Char, C0), line(Ln)))\n ),\n ( Tok1 == end_of_file\n -> List = []\n ; List = [Tok1|Tokens],\n tokens(C1, In, Tokens)\n ).\n\ntokens(C0, In, List) :-\n ( token(C0, In, C1, H)\n -> true\n ; nb_getval(line_number, Ln),\n char_code(Char, C0),\n throw(illegal_token(char_code(Char, C0), line(Ln)))\n ),\n ( H == end_of_file\n -> List = []\n ; List = [H|T],\n tokens(C1, In, T)\n ).\n\ntoken(-1, _, -1, end_of_file) :-\n !.\ntoken(0'., In, C, Token) :-\n ( peek_code(In, C0),\n ( e(C0)\n -> T1 = [0'0|T2],\n get_code(In, CN1)\n ; 0'0 =< C0,\n C0 =< 0'9,\n get_code(In, C1),\n integer_codes(C1, In, CN1, T1, T2)\n )\n -> ( exponent(CN1, In, C, T2)\n -> Type = double\n ; C = CN1,\n T2 = [],\n Type = decimal\n ),\n Token = numeric(Type, [0'0, 0'.|T1])\n ; nb_getval(line_number, Ln),\n get_code(In, C),\n !,\n Token = dot(Ln)\n ).\ntoken(0'#, In, C, Token) :-\n !,\n get_code(In, C1),\n skip_line(C1, In, C2),\n token(C2, In, C, Token).\ntoken(C0, In, C, Token) :-\n white_space(C0),\n !,\n get_code(In, C1),\n token(C1, In, C, Token).\ntoken(C0, In, C, Number) :-\n 0'0 =< C0,\n C0 =< 0'9,\n !,\n number_n(C0, In, C, Number).\ntoken(0'-, In, C, Number) :-\n !,\n number_n(0'-, In, C, Number).\ntoken(0'+, In, C, Number) :-\n !,\n number_n(0'+, In, C, Number).\ntoken(0'\", In, C, literal(Codes)) :-\n !,\n ( peek_code(In, 0'\")\n -> get_code(In, 0'\"),\n ( peek_code(In, 0'\")\n -> get_code(In, 0'\"),\n get_code(In, C1),\n dq_string(C1, In, C, Codes)\n ; get_code(In, C),\n Codes = []\n )\n ; get_code(In, C1),\n string_dq(C1, In, C, Codes)\n ).\ntoken(0'', In, C, literal(Codes)) :-\n !,\n ( peek_code(In, 0'')\n -> get_code(In, 0''),\n ( peek_code(In, 0'')\n -> get_code(In, 0''),\n get_code(In, C1),\n sq_string(C1, In, C, Codes)\n ; get_code(In, C),\n Codes = []\n )\n ; get_code(In, C1),\n string_sq(C1, In, C, Codes)\n ).\ntoken(0'?, In, C, uvar(Name)) :-\n !,\n get_code(In, C0),\n ( name(C0, In, C, Name)\n -> true\n ; C = C0,\n nb_getval(line_number, Ln),\n throw(empty_quickvar_name(line(Ln)))\n ).\ntoken(0'_, In, C, bnode(Name)) :-\n peek_code(In, 0':),\n !,\n get_code(In, _),\n get_code(In, C0),\n ( name(C0, In, C, Name)\n -> true\n ; C = C0,\n Name = ''\n ).\ntoken(0'<, In, C, lt_lt) :-\n peek_code(In, 0'<),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0'<, In, C, lt_eq) :-\n peek_string(In, 2, D),\n string_codes(D, [0'=, E]),\n ( white_space(E)\n ; punctuation(E, _)\n ),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0'<, In, C, lt_dash) :-\n peek_code(In, 0'-),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0'<, In, C, relative_uri(URI)) :-\n peek_code(In, C1),\n !,\n get_code(In, C1),\n iri_chars(C1, In, C, Codes),\n D = Codes,\n atom_codes(URI, D).\ntoken(0'>, In, C, gt_gt) :-\n peek_code(In, 0'>),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0'{, In, C, lb_pipe) :-\n peek_code(In, 0'|),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0'|, In, C, pipe_rb) :-\n peek_code(In, 0'}),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0':, In, C, Token) :-\n !,\n get_code(In, C0),\n ( local_name(C0, In, C, Name)\n -> Token = '':Name\n ; Token = '':'',\n C = C0\n ).\ntoken(0'@, In, C, atname(Name)) :-\n get_code(In, C0),\n token(C0, In, C, name(Name)),\n !.\ntoken(0'^, In, C, caret_caret) :-\n peek_code(In, 0'^),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(C0, In, C, Token) :-\n name(C0, In, C1, Name),\n !,\n ( C1 == 0':\n -> get_code(In, C2),\n ( local_name(C2, In, C, Name2)\n -> Token = (Name:Name2)\n ; Token = (Name:''),\n C = C2\n )\n ; Token = name(Name),\n C = C1\n ).\ntoken(C0, In, C, P) :-\n punctuation(C0, P),\n !,\n get_code(In, C).\n\nnumber_n(0'-, In, CN, numeric(T, [0'-|Codes])) :-\n !,\n get_code(In, C0),\n number_nn(C0, In, CN, numeric(T, Codes)).\nnumber_n(0'+, In, CN, numeric(T, [0'+|Codes])) :-\n !,\n get_code(In, C0),\n number_nn(C0, In, CN, numeric(T, Codes)).\nnumber_n(C0, In, CN, Value) :-\n number_nn(C0, In, CN, Value).\n\nnumber_nn(C, In, CN, numeric(Type, Codes)) :-\n integer_codes(C, In, CN0, Codes, T0),\n ( CN0 == 0'.,\n peek_code(In, C0),\n ( e(C0)\n -> T1 = [0'0|T2],\n get_code(In, CN1)\n ; 0'0 =< C0,\n C0 =< 0'9,\n get_code(In, C1),\n integer_codes(C1, In, CN1, T1, T2)\n ),\n T0 = [0'.|T1]\n -> ( exponent(CN1, In, CN, T2)\n -> Type = double\n ; CN = CN1,\n T2 = [],\n Type = decimal\n )\n ; ( exponent(CN0, In, CN, T0)\n -> Type = double\n ; T0 = [],\n CN = CN0,\n Type = integer\n )\n ).\n\ninteger_codes(C0, In, CN, [C0|T0], T) :-\n 0'0 =< C0,\n C0 =< 0'9,\n !,\n get_code(In, C1),\n integer_codes(C1, In, CN, T0, T).\ninteger_codes(CN, _, CN, T, T).\n\nexponent(C0, In, CN, [C0|T0]) :-\n e(C0),\n !,\n get_code(In, C1),\n optional_sign(C1, In, CN0, T0, T1),\n integer_codes(CN0, In, CN, T1, []),\n ( T1 = []\n -> nb_getval(line_number, Ln),\n throw(invalid_exponent(line(Ln)))\n ; true\n ).\n\noptional_sign(C0, In, CN, [C0|T], T) :-\n sign(C0),\n !,\n get_code(In, CN).\noptional_sign(CN, _, CN, T, T).\n\ne(0'e).\ne(0'E).\n\nsign(0'-).\nsign(0'+).\n\ndq_string(-1, _, _, []) :-\n !,\n nb_getval(line_number, Ln),\n throw(unexpected_end_of_input(line(Ln))).\ndq_string(0'\", In, C, []) :-\n ( retract(got_dq)\n -> true\n ; peek_code(In, 0'\"),\n get_code(In, _)\n ),\n ( retract(got_dq)\n -> assertz(got_dq)\n ; assertz(got_dq),\n peek_code(In, 0'\"),\n get_code(In, _),\n assertz(got_dq)\n ),\n !,\n ( peek_code(In, 0'\")\n -> nb_getval(line_number, Ln),\n throw(unexpected_double_quote(line(Ln)))\n ; true\n ),\n retractall(got_dq),\n get_code(In, C).\ndq_string(0'\", In, C, [0'\"|T]) :-\n !,\n ( retract(got_dq)\n -> C1 = 0'\"\n ; get_code(In, C1)\n ),\n dq_string(C1, In, C, T).\ndq_string(0'\\\\, In, C, [H|T]) :-\n ( retract(got_dq)\n -> C1 = 0'\"\n ; get_code(In, C1)\n ),\n !,\n string_escape(C1, In, C2, H),\n dq_string(C2, In, C, T).\ndq_string(C0, In, C, [C0|T]) :-\n ( retract(got_dq)\n -> C1 = 0'\"\n ; get_code(In, C1)\n ),\n dq_string(C1, In, C, T).\n\nsq_string(-1, _, _, []) :-\n !,\n nb_getval(line_number, Ln),\n throw(unexpected_end_of_input(line(Ln))).\nsq_string(0'', In, C, []) :-\n ( retract(got_sq)\n -> true\n ; peek_code(In, 0''),\n get_code(In, _)\n ),\n ( retract(got_sq)\n -> assertz(got_sq)\n ; assertz(got_sq),\n peek_code(In, 0''),\n get_code(In, _),\n assertz(got_sq)\n ),\n !,\n ( peek_code(In, 0'')\n -> nb_getval(line_number, Ln),\n throw(unexpected_single_quote(line(Ln)))\n ; true\n ),\n retractall(got_sq),\n get_code(In, C).\nsq_string(0'', In, C, [0''|T]) :-\n !,\n ( retract(got_sq)\n -> C1 = 0''\n ; get_code(In, C1)\n ),\n sq_string(C1, In, C, T).\nsq_string(0'\\\\, In, C, [H|T]) :-\n ( retract(got_sq)\n -> C1 = 0''\n ; get_code(In, C1)\n ),\n !,\n string_escape(C1, In, C2, H),\n sq_string(C2, In, C, T).\nsq_string(C0, In, C, [C0|T]) :-\n ( retract(got_sq)\n -> C1 = 0''\n ; get_code(In, C1)\n ),\n sq_string(C1, In, C, T).\n\nstring_dq(-1, _, _, []) :-\n !,\n nb_getval(line_number, Ln),\n throw(unexpected_end_of_input(line(Ln))).\nstring_dq(0'\\n, _, _, []) :-\n !,\n nb_getval(line_number, Ln),\n throw(unexpected_end_of_line(line(Ln))).\nstring_dq(0'\", In, C, []) :-\n !,\n get_code(In, C).\nstring_dq(0'\\\\, In, C, D) :-\n get_code(In, C1),\n !,\n string_escape(C1, In, C2, H),\n ( current_prolog_flag(windows, true),\n H > 0xFFFF\n -> E is (H-0x10000)>>10+0xD800,\n F is (H-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [H|T]\n ),\n string_dq(C2, In, C, T).\nstring_dq(C0, In, C, D) :-\n ( current_prolog_flag(windows, true),\n C0 > 0xFFFF\n -> E is (C0-0x10000)>>10+0xD800,\n F is (C0-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [C0|T]\n ),\n get_code(In, C1),\n string_dq(C1, In, C, T).\n\nstring_sq(-1, _, _, []) :-\n !,\n nb_getval(line_number, Ln),\n throw(unexpected_end_of_input(line(Ln))).\nstring_sq(0'', In, C, []) :-\n !,\n get_code(In, C).\nstring_sq(0'\\\\, In, C, D) :-\n get_code(In, C1),\n !,\n string_escape(C1, In, C2, H),\n ( current_prolog_flag(windows, true),\n H > 0xFFFF\n -> E is (H-0x10000)>>10+0xD800,\n F is (H-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [H|T]\n ),\n string_sq(C2, In, C, T).\nstring_sq(C0, In, C, D) :-\n ( current_prolog_flag(windows, true),\n C0 > 0xFFFF\n -> E is (C0-0x10000)>>10+0xD800,\n F is (C0-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [C0|T]\n ),\n get_code(In, C1),\n string_sq(C1, In, C, T).\n\nstring_escape(0't, In, C, 0'\\t) :-\n !,\n get_code(In, C).\nstring_escape(0'b, In, C, 0'\\b) :-\n !,\n get_code(In, C).\nstring_escape(0'n, In, C, 0'\\n) :-\n !,\n get_code(In, C).\nstring_escape(0'r, In, C, 0'\\r) :-\n !,\n get_code(In, C).\nstring_escape(0'f, In, C, 0'\\f) :-\n !,\n get_code(In, C).\nstring_escape(0'\", In, C, 0'\") :-\n !,\n get_code(In, C).\nstring_escape(0'', In, C, 0'') :-\n !,\n get_code(In, C).\nstring_escape(0'\\\\, In, C, 0'\\\\) :-\n !,\n get_code(In, C).\nstring_escape(0'u, In, C, Code) :-\n !,\n get_hhhh(In, A),\n ( 0xD800 =< A,\n A =< 0xDBFF\n -> get_code(In, 0'\\\\),\n get_code(In, 0'u),\n get_hhhh(In, B),\n Code is 0x10000+(A-0xD800)*0x400+(B-0xDC00)\n ; Code is A\n ),\n get_code(In, C).\nstring_escape(0'U, In, C, Code) :-\n !,\n get_hhhh(In, Code0),\n get_hhhh(In, Code1),\n Code is Code0 << 16 + Code1,\n get_code(In, C).\nstring_escape(C, _, _, _) :-\n nb_getval(line_number, Ln),\n atom_codes(A, [0'\\\\, C]),\n throw(illegal_string_escape_sequence(A, line(Ln))).\n\nget_hhhh(In, Code) :-\n get_code(In, C1),\n code_type(C1, xdigit(D1)),\n get_code(In, C2),\n code_type(C2, xdigit(D2)),\n get_code(In, C3),\n code_type(C3, xdigit(D3)),\n get_code(In, C4),\n code_type(C4, xdigit(D4)),\n Code is D1<<12+D2<<8+D3<<4+D4.\n\nlanguage(C0, In, C, [C0|Codes]) :-\n code_type(C0, lower),\n get_code(In, C1),\n lwr_word(C1, In, C2, Codes, Tail),\n sub_langs(C2, In, C, Tail, []).\n\nlwr_word(C0, In, C, [C0|T0], T) :-\n code_type(C0, lower),\n !,\n get_code(In, C1),\n lwr_word(C1, In, C, T0, T).\nlwr_word(C, _, C, T, T).\n\nsub_langs(0'-, In, C, [0'-, C1|Codes], T) :-\n get_code(In, C1),\n lwrdig(C1),\n !,\n get_code(In, C2),\n lwrdigs(C2, In, C3, Codes, Tail),\n sub_langs(C3, In, C, Tail, T).\nsub_langs(C, _, C, T, T).\n\nlwrdig(C) :-\n code_type(C, lower),\n !.\nlwrdig(C) :-\n code_type(C, digit).\n\nlwrdigs(C0, In, C, [C0|T0], T) :-\n lwrdig(C0),\n !,\n get_code(In, C1),\n lwr_word(C1, In, C, T0, T).\nlwrdigs(C, _, C, T, T).\n\niri_chars(0'>, In, C, []) :-\n !,\n get_code(In, C).\niri_chars(0'\\\\, In, C, D) :-\n !,\n get_code(In, C1),\n iri_escape(C1, In, C2, H),\n \\+non_iri_char(H),\n ( current_prolog_flag(windows, true),\n H > 0xFFFF\n -> E is (H-0x10000)>>10+0xD800,\n F is (H-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [H|T]\n ),\n iri_chars(C2, In, C, T).\niri_chars(0'%, In, C, [0'%, C1, C2|T]) :-\n !,\n get_code(In, C1),\n code_type(C1, xdigit(_)),\n get_code(In, C2),\n code_type(C2, xdigit(_)),\n get_code(In, C3),\n iri_chars(C3, In, C, T).\niri_chars(-1, _, _, _) :-\n !,\n fail.\niri_chars(C0, In, C, D) :-\n \\+non_iri_char(C0),\n ( current_prolog_flag(windows, true),\n C0 > 0xFFFF\n -> E is (C0-0x10000)>>10+0xD800,\n F is (C0-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [C0|T]\n ),\n get_code(In, C1),\n iri_chars(C1, In, C, T).\n\niri_escape(0'u, In, C, Code) :-\n !,\n get_hhhh(In, A),\n ( 0xD800 =< A,\n A =< 0xDBFF\n -> get_code(In, 0'\\\\),\n get_code(In, 0'u),\n get_hhhh(In, B),\n Code is 0x10000+(A-0xD800)*0x400+(B-0xDC00)\n ; Code is A\n ),\n get_code(In, C).\niri_escape(0'U, In, C, Code) :-\n !,\n get_hhhh(In, Code0),\n get_hhhh(In, Code1),\n Code is Code0 << 16 + Code1,\n get_code(In, C).\niri_escape(C, _, _, _) :-\n nb_getval(line_number, Ln),\n atom_codes(A, [0'\\\\, C]),\n throw(illegal_iri_escape_sequence(A, line(Ln))).\n\nnon_iri_char(C) :-\n 0x00 =< C,\n C =< 0x20,\n !.\nnon_iri_char(0'<).\nnon_iri_char(0'>).\nnon_iri_char(0'\").\nnon_iri_char(0'{).\nnon_iri_char(0'}).\nnon_iri_char(0'|).\nnon_iri_char(0'^).\nnon_iri_char(0'`).\nnon_iri_char(0'\\\\).\n\nname(C0, In, C, Atom) :-\n name_start_char(C0),\n get_code(In, C1),\n name_chars(C1, In, C, T),\n atom_codes(Atom, [C0|T]).\n\nname_start_char(C) :-\n pn_chars_base(C),\n !.\nname_start_char(0'_).\nname_start_char(C) :-\n code_type(C, digit).\n\nname_chars(0'., In, C, [0'.|T]) :-\n peek_code(In, C1),\n pn_chars(C1),\n !,\n get_code(In, C1),\n name_chars(C1, In, C, T).\nname_chars(C0, In, C, [C0|T]) :-\n pn_chars(C0),\n !,\n get_code(In, C1),\n name_chars(C1, In, C, T).\nname_chars(C, _, C, []).\n\npn_chars_base(C) :-\n code_type(C, alpha),\n !.\npn_chars_base(C) :-\n 0xC0 =< C,\n C =< 0xD6,\n !.\npn_chars_base(C) :-\n 0xD8 =< C,\n C =< 0xF6,\n !.\npn_chars_base(C) :-\n 0xF8 =< C,\n C =< 0x2FF,\n !.\npn_chars_base(C) :-\n 0x370 =< C,\n C =< 0x37D,\n !.\npn_chars_base(C) :-\n 0x37F =< C,\n C =< 0x1FFF,\n !.\npn_chars_base(C) :-\n 0x200C =< C,\n C =< 0x200D,\n !.\npn_chars_base(C) :-\n 0x2070 =< C,\n C =< 0x218F,\n !.\npn_chars_base(C) :-\n 0x2C00 =< C,\n C =< 0x2FEF,\n !.\npn_chars_base(C) :-\n 0x3001 =< C,\n C =< 0xD7FF,\n !.\npn_chars_base(C) :-\n 0xF900 =< C,\n C =< 0xFDCF,\n !.\npn_chars_base(C) :-\n 0xFDF0 =< C,\n C =< 0xFFFD,\n !.\npn_chars_base(C) :-\n 0x10000 =< C,\n C =< 0xEFFFF.\n\npn_chars(C) :-\n code_type(C, csym),\n !.\npn_chars(C) :-\n pn_chars_base(C),\n !.\npn_chars(0'-) :-\n !.\npn_chars(0xB7) :-\n !.\npn_chars(C) :-\n 0x0300 =< C,\n C =< 0x036F,\n !.\npn_chars(C) :-\n 0x203F =< C,\n C =< 0x2040.\n\nlocal_name(0'\\\\, In, C, Atom) :-\n !,\n get_code(In, C0),\n reserved_char_escapes(C0),\n get_code(In, C1),\n local_name_chars(C1, In, C, T),\n atom_codes(Atom, [C0|T]).\nlocal_name(0'%, In, C, Atom) :-\n !,\n get_code(In, C0),\n code_type(C0, xdigit(_)),\n get_code(In, C1),\n code_type(C1, xdigit(_)),\n get_code(In, C2),\n local_name_chars(C2, In, C, T),\n atom_codes(Atom, [0'%, C0, C1|T]).\nlocal_name(C0, In, C, Atom) :-\n local_name_start_char(C0),\n get_code(In, C1),\n local_name_chars(C1, In, C, T),\n atom_codes(Atom, [C0|T]).\n\nlocal_name_chars(0'\\\\, In, C, [C0|T]) :-\n !,\n get_code(In, C0),\n reserved_char_escapes(C0),\n get_code(In, C1),\n local_name_chars(C1, In, C, T).\nlocal_name_chars(0'%, In, C, [0'%, C0, C1|T]) :-\n !,\n get_code(In, C0),\n code_type(C0, xdigit(_)),\n get_code(In, C1),\n code_type(C1, xdigit(_)),\n get_code(In, C2),\n local_name_chars(C2, In, C, T).\nlocal_name_chars(0'., In, C, [0'.|T]) :-\n peek_code(In, C1),\n ( local_name_char(C1)\n ; C1 = 0'.\n ),\n !,\n get_code(In, C1),\n local_name_chars(C1, In, C, T).\nlocal_name_chars(C0, In, C, [C0|T]) :-\n local_name_char(C0),\n !,\n get_code(In, C1),\n local_name_chars(C1, In, C, T).\nlocal_name_chars(C, _, C, []).\n\nlocal_name_start_char(C) :-\n name_start_char(C),\n !.\nlocal_name_start_char(0':).\nlocal_name_start_char(0'%).\nlocal_name_start_char(0'\\\\).\n\nlocal_name_char(C) :-\n pn_chars(C),\n !.\nlocal_name_char(0':).\nlocal_name_char(0'%).\nlocal_name_char(0'\\\\).\n\nreserved_char_escapes(0'~).\nreserved_char_escapes(0'.).\nreserved_char_escapes(0'-).\nreserved_char_escapes(0'!).\nreserved_char_escapes(0'$).\nreserved_char_escapes(0'&).\nreserved_char_escapes(0'').\nreserved_char_escapes(0'().\nreserved_char_escapes(0')).\nreserved_char_escapes(0'*).\nreserved_char_escapes(0'+).\nreserved_char_escapes(0',).\nreserved_char_escapes(0';).\nreserved_char_escapes(0'=).\nreserved_char_escapes(0'/).\nreserved_char_escapes(0'?).\nreserved_char_escapes(0'#).\nreserved_char_escapes(0'@).\nreserved_char_escapes(0'%).\nreserved_char_escapes(0'_).\n\npunctuation(0'(, '(').\npunctuation(0'), ')').\npunctuation(0'[, '[').\npunctuation(0'], ']').\npunctuation(0',, ',').\npunctuation(0':, ':').\npunctuation(0';, ';').\npunctuation(0'{, '{').\npunctuation(0'}, '}').\npunctuation(0'?, '?').\npunctuation(0'!, '!').\npunctuation(0'^, '^').\npunctuation(0'=, '=').\npunctuation(0'<, '<').\npunctuation(0'>, '>').\npunctuation(0'$, '$').\n\nskip_line(-1, _, -1) :-\n !.\nskip_line(0xA, In, C) :-\n !,\n cnt(line_number),\n get_code(In, C).\nskip_line(0xD, In, C) :-\n !,\n get_code(In, C).\nskip_line(_, In, C) :-\n get_code(In, C1),\n skip_line(C1, In, C).\n\nwhite_space(0x9).\nwhite_space(0xA) :-\n cnt(line_number).\nwhite_space(0xD).\nwhite_space(0x20).\n\n%\n% Reasoning output\n%\n\nw0([]) :-\n !.\nw0(['--image', _|A]) :-\n !,\n w0(A).\nw0([A|B]) :-\n ( \\+sub_atom(A, 1, _, _, '\"'),\n sub_atom(A, _, 1, _, ' '),\n \\+sub_atom(A, _, _, 1, '\"')\n -> format(' \"~w\"', [A])\n ; format(' ~w', [A])\n ),\n w0(B).\n\nw1([]) :-\n !.\nw1([A|B]) :-\n ( \\+sub_atom(A, 1, _, _, '\"'),\n sub_atom(A, _, 1, _, ' '),\n \\+sub_atom(A, _, _, 1, '\"')\n -> format(' \"~w\"', [A])\n ; format(' ~w', [A])\n ),\n w1(B).\n\nwh :-\n ( keep_skolem(_)\n -> nb_getval(var_ns, Sns),\n put_pfx('var', Sns)\n ; true\n ),\n ( flag('no-qnames')\n -> true\n ; nb_setval(wpfx, false),\n forall(\n ( pfx(A, B),\n \\+wpfx(A)\n ),\n ( format('@prefix ~w ~w.~n',[A,B]),\n assertz(wpfx(A)),\n nb_setval(wpfx, true)\n )\n ),\n ( \\+flag('pass-only-new'),\n nb_getval(wpfx, true)\n -> nl\n ; true\n )\n ).\n\nw3 :-\n flag(blogic),\n flag(n3p),\n ( answer(B1, B2, B3),\n relabel([B1, B2, B3], [C1, C2, C3]),\n djiti_answer(answer(C), answer(C1, C2, C3)),\n indent,\n writeq(C),\n ws(C),\n write('.'),\n nl,\n cnt(output_statements),\n fail\n ; nl\n ).\nw3 :-\n wh,\n nb_setval(fdepth, 0),\n nb_setval(pdepth, 0),\n nb_setval(cdepth, 0),\n flag(nope),\n !,\n ( query(Q, A),\n ( Q = \\+(R)\n -> \\+catch(call(R), _, fail)\n ; catch(call(Q), _, fail)\n ),\n nb_getval(wn, W),\n labelvars(A, W, N, some),\n nb_setval(wn, N),\n relabel(A, B),\n indent,\n wt(B),\n ws(B),\n write('.'),\n nl,\n ( A = (_, _),\n conj_list(A, L)\n -> length(L, I),\n cnt(output_statements, I)\n ; cnt(output_statements)\n ),\n fail\n ; true\n ),\n ( answer(B1, B2, B3),\n relabel([B1, B2, B3], [C1, C2, C3]),\n djiti_answer(answer(C), answer(C1, C2, C3)),\n indent,\n wt(C),\n ws(C),\n write('.'),\n nl,\n cnt(output_statements),\n fail\n ; nl\n ).\nw3 :-\n ( prfstep(answer(_, _, _), _, _, _, _, _, _),\n !,\n nb_setval(empty_gives, false),\n indent,\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'proof', '>'], Sk),\n wp(Sk),\n write(' '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Proof>'),\n write(', '),\n wp('<http://www.w3.org/2000/10/swap/reason#Conjunction>'),\n write(';'),\n indentation(2),\n nl,\n indent,\n ( prfstep(answer(_, _, _), B, Pnd, Cn, R, _, A),\n R =.. [P, S, O1],\n djiti_answer(answer(O), O1),\n Rule =.. [P, S, O],\n djiti_answer(answer(C), Cn),\n nb_setval(empty_gives, C),\n \\+got_wi(A, B, Pnd, C, Rule),\n assertz(got_wi(A, B, Pnd, C, Rule)),\n wp('<http://www.w3.org/2000/10/swap/reason#component>'),\n write(' '),\n wi(A, B, C, Rule),\n write(';'),\n nl,\n indent,\n fail\n ; retractall(got_wi(_, _, _, _, _))\n ),\n wp('<http://www.w3.org/2000/10/swap/reason#gives>'),\n ( nb_getval(empty_gives, true)\n -> write(' true.')\n ; write(' {'),\n indentation(2),\n ( prfstep(answer(B1, B2, B3), _, _, _, _, _, _),\n relabel([B1, B2, B3], [C1, C2, C3]),\n djiti_answer(answer(C), answer(C1, C2, C3)),\n nl,\n indent,\n getvars(C, D),\n ( C = '<http://www.w3.org/2000/10/swap/log#implies>'(_, _)\n -> Q = allv\n ; Q = some\n ),\n wq(D, Q),\n wt(C),\n ws(C),\n write('.'),\n cnt(output_statements),\n fail\n ; true\n ),\n indentation(-2),\n nl,\n indent,\n write('}.')\n ),\n indentation(-2),\n nl,\n nl\n ; true\n ),\n ( nb_getval(lemma_count, Lco),\n nb_getval(lemma_cursor, Lcu),\n Lcu < Lco\n -> repeat,\n cnt(lemma_cursor),\n nb_getval(lemma_cursor, Cursor),\n lemma(Cursor, Ai, Bi, Ci, _, Di),\n indent,\n wj(Cursor, Ai, Bi, Ci, Di),\n nl,\n nl,\n nb_getval(lemma_count, Cnt),\n Cursor = Cnt,\n !\n ; true\n ).\n\nwi('<>', _, rule(_, _, A), _) :- % wi(Source, Premise, Conclusion, Rule)\n !,\n write('[ '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Fact>'),\n write('; '),\n wp('<http://www.w3.org/2000/10/swap/reason#gives>'),\n write(' '),\n wg(A),\n write(']').\nwi(A, B, C, Rule) :-\n term_index(B-C, Ind),\n ( lemma(Cnt, A, B, C, Ind, Rule)\n -> true\n ; cnt(lemma_count),\n nb_getval(lemma_count, Cnt),\n assertz(lemma(Cnt, A, B, C, Ind, Rule))\n ),\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'lemma', Cnt, '>'], Sk),\n wp(Sk).\n\nwj(Cnt, A, true, C, Rule) :- % wj(Count, Source, Premise, Conclusion, Rule)\n var(Rule),\n C \\= '<http://www.w3.org/2000/10/swap/log#implies>'(_, _),\n !,\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'lemma', Cnt, '>'], Sk),\n wp(Sk),\n write(' '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Extraction>'),\n writeln(';'),\n indentation(2),\n indent,\n wp('<http://www.w3.org/2000/10/swap/reason#gives>'),\n ( C = true\n -> write(' true;')\n ; write(' {'),\n nl,\n indentation(2),\n indent,\n ( C = rule(PVars, EVars, Rule)\n -> wq(PVars, allv),\n wq(EVars, some),\n wt(Rule)\n ; labelvars([A, C], 0, _, avar),\n getvars(C, D),\n wq(D, some),\n wt(C)\n ),\n ws(C),\n write('.'),\n nl,\n indentation(-2),\n indent,\n write('};')\n ),\n nl,\n indent,\n wp('<http://www.w3.org/2000/10/swap/reason#because>'),\n write(' [ '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Parsing>'),\n write('; '),\n wp('<http://www.w3.org/2000/10/swap/reason#source>'),\n write(' '),\n ( C = rule(_, _, Rl),\n Rl =.. [P, S, O],\n '<http://www.w3.org/2000/10/swap/reason#source>'(triple(S, P, O), Src)\n -> wt(Src)\n ; ( C =.. [P, S, O],\n '<http://www.w3.org/2000/10/swap/reason#source>'(triple(S, P, O), Src)\n -> wt(Src)\n ; wt(A)\n )\n ),\n write('].'),\n indentation(-2).\nwj(Cnt, A, B, C, Rule) :-\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'lemma', Cnt, '>'], Sk),\n wp(Sk),\n write(' '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Inference>'),\n writeln(';'),\n indentation(2),\n indent,\n wp('<http://www.w3.org/2000/10/swap/reason#gives>'),\n ( C = true\n -> write(' true;')\n ; write(' {'),\n nl,\n Rule = '<http://www.w3.org/2000/10/swap/log#implies>'(Prem, Conc),\n unifiable(Prem, B, Bs),\n ( unifiable(Conc, C, Cs)\n -> true\n ; Cs = []\n ),\n append(Bs, Cs, Ds),\n sort(Ds, Bindings),\n term_variables(Prem, PVars),\n term_variables(Conc, CVars),\n nb_getval(wn, W),\n labelvars([A, B, C], W, N, some),\n nb_setval(wn, N),\n labelvars([Rule, PVars, CVars], 0, _, avar),\n findall(V,\n ( member(V, CVars),\n \\+member(V, PVars)\n ),\n EVars\n ),\n getvars(C, D),\n ( C = '<http://www.w3.org/2000/10/swap/log#implies>'(_, _)\n -> Q = allv\n ; Q = some\n ),\n indentation(2),\n indent,\n wq(D, Q),\n wt(C),\n ws(C),\n write('.'),\n nl,\n indentation(-2),\n indent,\n write('};')\n ),\n nl,\n indent,\n wp('<http://www.w3.org/2000/10/swap/reason#evidence>'),\n write(' ('),\n indentation(2),\n wr(B),\n indentation(-2),\n nl,\n indent,\n write(');'),\n retractall(got_wi(_, _, _, _, _)),\n nl,\n indent,\n wb(Bindings),\n wp('<http://www.w3.org/2000/10/swap/reason#rule>'),\n write(' '),\n wi(A, true, rule(PVars, EVars, Rule), _),\n write('.'),\n indentation(-2).\n\nwr(exopred(P, S, O)) :-\n atom(P),\n !,\n U =.. [P, S, O],\n wr(U).\nwr((X, Y)) :-\n !,\n wr(X),\n wr(Y).\nwr(Z) :-\n prfstep(Z, Y, _, Q, Rule, _, X),\n !,\n nl,\n indent,\n wi(X, Y, Q, Rule).\nwr(Y) :-\n nl,\n indent,\n write('[ '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Fact>'),\n write('; '),\n wp('<http://www.w3.org/2000/10/swap/reason#gives>'),\n write(' '),\n ( Y = true\n -> wt(Y)\n ; write('{'),\n labelvars(Y, 0, _, avar),\n getvars(Y, Z),\n wq(Z, some),\n X = Y,\n wt(X),\n write('}')\n ),\n write(']').\n\nwt(X) :-\n var(X),\n !,\n write('?'),\n write(X).\nwt(X) :-\n functor(X, _, A),\n ( A = 0,\n !,\n wt0(X)\n ; A = 1,\n !,\n wt1(X)\n ; A = 2,\n !,\n wt2(X)\n ; wtn(X)\n ).\n\nwt0(!) :-\n !,\n write('(\"!\") '),\n wp('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'),\n write(' true').\nwt0(fail) :-\n !,\n write('(\"fail\") '),\n wp('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'),\n write(' true').\nwt0([]) :-\n !,\n write('()').\nwt0(X) :-\n number(X),\n !,\n ( flag('no-numerals')\n -> dtlit([U, V], X),\n dtlit([U, V], W),\n wt(W)\n ; write(X)\n ).\nwt0(X) :-\n atom(X),\n atom_concat(some, Y, X),\n !,\n ( \\+flag('no-qvars')\n -> ( rule_uvar(L),\n ( ncllit\n -> ( memberchk(X, L)\n -> true\n ; retract(rule_uvar(L)),\n assertz(rule_uvar([X|L]))\n )\n ; memberchk(X, L)\n )\n -> write('?U_')\n ; write('_:sk_')\n ),\n write(Y)\n ; atomic_list_concat(['<http://eyereasoner.github.io/var#some_', Y, '>'], Z),\n wt0(Z)\n ).\nwt0(X) :-\n atom(X),\n atom_concat(allv, Y, X),\n !,\n ( \\+flag('no-qvars'),\n \\+flag('pass-all-ground')\n -> write('?U_'),\n write(Y)\n ; atomic_list_concat(['<http://eyereasoner.github.io/var#all_', Y, '>'], Z),\n wt0(Z)\n ).\nwt0(X) :-\n atom(X),\n atom_concat(avar, Y, X),\n !,\n atomic_list_concat(['<http://eyereasoner.github.io/var#x_', Y, '>'], Z),\n wt0(Z).\nwt0(X) :-\n flag(nope),\n \\+flag('pass-all-ground'),\n \\+keep_skolem(X),\n nb_getval(var_ns, Sns),\n atom(X),\n sub_atom(X, 1, I, _, Sns),\n J is I+1,\n sub_atom(X, J, _, 1, Y),\n ( getlist(X, M)\n -> wt(M)\n ; ( rule_uvar(L),\n ( ncllit\n -> ( memberchk(Y, L)\n -> true\n ; retract(rule_uvar(L)),\n assertz(rule_uvar([Y|L]))\n )\n ; memberchk(Y, L)\n )\n -> ( ( sub_atom(Y, 0, 2, _, 'e_')\n ; sub_atom(Y, 0, 3, _, 'bn_')\n )\n -> write('_:')\n ; sub_atom(Y, 0, 2, _, Z),\n memberchk(Z, ['x_', 't_']),\n write('?')\n )\n ; ( \\+flag('no-qvars')\n -> true\n ; flag('quantify', Prefix),\n sub_atom(X, 1, _, _, Prefix)\n ),\n write('_:')\n ),\n write(Y),\n ( sub_atom(Y, 0, 2, _, 'x_')\n -> write('_'),\n nb_getval(rn, N),\n write(N)\n ; true\n )\n ),\n !.\nwt0(X) :-\n flag('quantify', Prefix),\n flag(nope),\n atom(X),\n sub_atom(X, 1, _, _, Prefix),\n !,\n ( getlist(X, M)\n -> wt(M)\n ; '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(Y, ['quantify', Prefix, X]),\n wt0(Y)\n ).\nwt0(X) :-\n ( wtcache(X, W)\n -> true\n ; ( \\+flag('no-qnames'),\n atom(X),\n ( sub_atom(X, I, 1, J, '#')\n -> J > 1,\n sub_atom(X, 0, I, _, C),\n atom_concat(C, '#>', D)\n ; ( sub_atom_last(X, I, 1, J, '/')\n -> J > 1,\n sub_atom(X, 0, I, _, C),\n atom_concat(C, '/>', D)\n ; J = 1,\n D = X\n )\n ),\n pfx(E, D),\n K is J-1,\n sub_atom(X, _, K, 1, F)\n -> atom_concat(E, F, W),\n assertz(wtcache(X, W))\n ; ( \\+flag(strings),\n atom(X),\n \\+ (sub_atom(X, 0, 1, _, '<'), sub_atom(X, _, 1, 0, '>')),\n X \\= true,\n X \\= false\n -> W = literal(X, type('<http://www.w3.org/2001/XMLSchema#string>'))\n ; W = X\n )\n )\n ),\n ( W = literal(X, type('<http://www.w3.org/2001/XMLSchema#string>'))\n -> wt2(W)\n ; ( current_prolog_flag(windows, true)\n -> atom_codes(W, U),\n escape_unicode(U, V),\n atom_codes(Z, V)\n ; Z = W\n ),\n ( atom(Z)\n -> write(Z)\n ; '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(A, [blob, Z]),\n wt(A)\n )\n ).\n\nwt1(set(X)) :-\n !,\n write('($'),\n wl(X),\n write(' $)').\nwt1('$VAR'(X)) :-\n !,\n write('?V'),\n write(X).\nwt1(X) :-\n X =.. [B|C],\n ( atom(B),\n \\+ (sub_atom(B, 0, 1, _, '<'), sub_atom(B, _, 1, 0, '>'))\n -> write('\"'),\n writeq(X),\n write('\"')\n ; wt(C),\n write(' '),\n wp(B),\n write(' true')\n ).\n\nwt2((X, Y)) :-\n !,\n ( atomic(X),\n X \\= '!'\n -> wt2([X, Y]),\n write(' '),\n wt0('<http://eulersharp.sourceforge.net/2003/03swap/prolog#conjunction>'),\n write(' true')\n ; wt(X),\n ws(X),\n write('.'),\n ( ( flag(strings)\n ; flag(nope)\n )\n -> write(' ')\n ; nl,\n indent\n ),\n wt(Y)\n ).\nwt2([X|Y]) :-\n !,\n ( \\+last_tail([X|Y], [])\n -> write('[ '),\n wt0('<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>'),\n write(' '),\n wg(X),\n write('; '),\n wt0('<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'),\n write(' '),\n wt(Y),\n write(']')\n ; write('('),\n wg(X),\n wl(Y),\n write(')')\n ).\nwt2(literal(X, lang(Y))) :-\n !,\n write('\"'),\n ( current_prolog_flag(windows, true)\n -> atom_codes(X, U),\n escape_unicode(U, V),\n atom_codes(Z, V)\n ; Z = X\n ),\n write(Z),\n write('\"@'),\n write(Y).\nwt2(literal(X, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n !,\n ( sub_atom(X, _, 2, _, '\\\\n')\n -> write('\"\"\"'),\n atom_codes(X, C),\n escape_string(D, C),\n atom_codes(Y, D),\n ( current_prolog_flag(windows, true)\n -> atom_codes(Y, U),\n escape_unicode(U, V),\n atom_codes(Z, V)\n ; Z = Y\n ),\n write(Z),\n write('\"\"\"')\n ; write('\"'),\n ( current_prolog_flag(windows, true)\n -> atom_codes(X, U),\n escape_unicode(U, V),\n atom_codes(Z, V)\n ; Z = X\n ),\n write(Z),\n write('\"')\n ).\nwt2(literal(X, type(Y))) :-\n !,\n write('\"'),\n ( current_prolog_flag(windows, true)\n -> atom_codes(X, U),\n escape_unicode(U, V),\n atom_codes(Z, V)\n ; Z = X\n ),\n write(Z),\n write('\"^^'),\n wt(Y).\nwt2(rdiv(X, Y)) :-\n number_codes(Y, [0'1|Z]),\n lzero(Z, Z),\n !,\n ( Z = []\n -> F = '~d.0'\n ; length(Z, N),\n number_codes(X, U),\n ( length(U, N)\n -> F = '0.~d'\n ; atomic_list_concat(['~', N, 'd'], F)\n )\n ),\n ( flag('no-numerals')\n -> write('\"')\n ; true\n ),\n format(F, [X]),\n ( flag('no-numerals')\n -> write('\"^^'),\n wt0('<http://www.w3.org/2001/XMLSchema#decimal>')\n ; true\n ).\nwt2(rdiv(X, Y)) :-\n !,\n ( flag('no-numerals')\n -> write('\"')\n ; true\n ),\n format('~g', [rdiv(X, Y)]),\n ( flag('no-numerals')\n -> write('\"^^'),\n wt0('<http://www.w3.org/2001/XMLSchema#decimal>')\n ; true\n ).\nwt2('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#biconditional>'([X|Y], Z)) :-\n flag(nope),\n !,\n '<http://www.w3.org/2000/10/swap/log#conjunction>'(Y, U),\n write('{'),\n wt(U),\n write('. _: '),\n wp('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#true>'),\n write(' '),\n wt(Z),\n write('} '),\n wp('<http://www.w3.org/2000/10/swap/log#implies>'),\n write(' {'),\n wt(X),\n write('}').\nwt2('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#conditional>'([X|Y], Z)) :-\n flag(nope),\n !,\n '<http://www.w3.org/2000/10/swap/log#conjunction>'(Y, U),\n write('{'),\n wt(U),\n write('. _: '),\n wp('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#true>'),\n write(' '),\n wt(Z),\n write('} '),\n wp('<http://www.w3.org/2000/10/swap/log#implies>'),\n write(' {'),\n wt(X),\n write('}').\nwt2('<http://www.w3.org/2000/10/swap/log#implies>'(X, Y)) :-\n ( flag(nope)\n -> U = X\n ; ( X = when(A, B)\n -> conj_append(B, istep(_, _, _, _), C),\n U = when(A, C)\n ; conj_append(X, istep(_, _, _, _), U)\n )\n ),\n ( flag('rule-histogram')\n -> ( U = when(D, E)\n -> conj_append(E, pstep(_), F),\n Z = when(D, F)\n ; conj_append(U, pstep(_), Z)\n )\n ; Z = U\n ),\n ( rule_uvar(R)\n -> true\n ; R = [],\n cnt(rn)\n ),\n ( nb_getval(pdepth, 0),\n nb_getval(cdepth, 0)\n -> assertz(rule_uvar(R))\n ; true\n ),\n ( catch(clause(Y, Z), _, fail)\n -> ( nb_getval(fdepth, 0)\n -> assertz(ncllit)\n ; true\n ),\n wg(Y),\n write(' <= '),\n wg(X),\n ( nb_getval(fdepth, 0)\n -> retract(ncllit)\n ; true\n )\n ; ( clause('<http://www.w3.org/2000/10/swap/log#implies>'(X, Y, _, _, _, _), true)\n -> wg(X),\n write(' => '),\n wg(Y)\n ; ( nb_getval(fdepth, 0)\n -> assertz(ncllit)\n ; true\n ),\n ( \\+atom(X)\n -> nb_getval(pdepth, PD),\n PD1 is PD+1,\n nb_setval(pdepth, PD1)\n ; true\n ),\n wg(X),\n ( \\+atom(X)\n -> nb_setval(pdepth, PD)\n ; true\n ),\n ( nb_getval(fdepth, 0)\n -> retract(ncllit)\n ; true\n ),\n write(' => '),\n ( \\+atom(Y)\n -> nb_getval(cdepth, CD),\n CD1 is CD+1,\n nb_setval(cdepth, CD1)\n ; true\n ),\n wg(Y),\n ( \\+atom(Y)\n -> nb_setval(cdepth, CD)\n ; true\n )\n )\n ),\n ( nb_getval(pdepth, 0),\n nb_getval(cdepth, 0)\n -> retract(rule_uvar(_))\n ; true\n ),\n !.\nwt2(':-'(X, Y)) :-\n ( rule_uvar(R)\n -> true\n ; R = [],\n cnt(rn)\n ),\n ( nb_getval(fdepth, 0)\n -> assertz(ncllit)\n ; true\n ),\n assertz(rule_uvar(R)),\n ( Y = true\n -> wt(X)\n ; wg(X),\n write(' <= '),\n wg(Y),\n retract(rule_uvar(U)),\n ( U \\= [],\n retract(rule_uvar(V)),\n append(U, V, W)\n -> assertz(rule_uvar(W))\n ; true\n )\n ),\n ( nb_getval(fdepth, 0)\n -> retract(ncllit)\n ; true\n ),\n !.\nwt2(is(O, T)) :-\n !,\n ( number(T),\n T < 0\n -> P = -,\n Q is -T,\n S = [Q]\n ; T =.. [P|S]\n ),\n wg(S),\n write(' '),\n wp(P),\n write(' '),\n wg(O).\nwt2(prolog:X) :-\n !,\n ( X = '\\';\\''\n -> Y = disjunction\n ; prolog_sym(Y, X, _)\n ),\n atomic_list_concat(['<http://eulersharp.sourceforge.net/2003/03swap/prolog#', Y, '>'], Z),\n wt0(Z).\nwt2(X) :-\n X =.. [P, S, O],\n ( atom(P),\n \\+ (sub_atom(P, 0, 1, _, '<'), sub_atom(P, _, 1, 0, '>')),\n \\+sub_atom(P, 0, _, _, avar),\n \\+sub_atom(P, 0, _, _, some)\n -> write('\"'),\n writeq(X),\n write('\"')\n ; wg(S),\n write(' '),\n wp(P),\n write(' '),\n wg(O)\n ).\n\nwtn(exopred(P, S, O)) :-\n !,\n ( atom(P)\n -> X =.. [P, S, O],\n wt2(X)\n ; wg(S),\n write(' '),\n wg(P),\n write(' '),\n wg(O)\n ).\nwtn(triple(S, P, O)) :-\n !,\n write('<<'),\n wg(S),\n write(' '),\n wp(P),\n write(' '),\n wg(O),\n write('>>').\nwtn(X) :-\n X =.. [B|C],\n ( atom(B),\n \\+ (sub_atom(B, 0, 1, _, '<'), sub_atom(B, _, 1, 0, '>'))\n -> write('\"'),\n writeq(X),\n write('\"')\n ; wt(C),\n write(' '),\n wp(B),\n write(' true')\n ).\n\nwg(X) :-\n var(X),\n !,\n write('?'),\n write(X).\nwg(X) :-\n functor(X, F, A),\n ( ( F = exopred,\n !\n ; prolog_sym(_, F, _),\n F \\= true,\n F \\= false,\n F \\= '-',\n F \\= /,\n !\n ; A = 2,\n F \\= '.',\n F \\= '[|]',\n F \\= ':',\n F \\= literal,\n F \\= rdiv,\n ( sub_atom(F, 0, 1, _, '<'),\n sub_atom(F, _, 1, 0, '>')\n ; F = ':-'\n )\n )\n -> write('{'),\n indentation(1),\n nb_getval(fdepth, D),\n E is D+1,\n nb_setval(fdepth, E),\n wt(X),\n nb_setval(fdepth, D),\n indentation(-1),\n write('}')\n ; wt(X)\n ).\n\nwp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>') :-\n \\+flag('no-qnames'),\n !,\n write('a').\nwp('<http://www.w3.org/2000/10/swap/log#implies>') :-\n \\+flag('no-qnames'),\n !,\n write('=>').\nwp(':-') :-\n \\+flag('no-qnames'),\n !,\n write('<=').\nwp(X) :-\n ( prolog_sym(Y, X, _),\n X \\= true,\n X \\= false\n -> atomic_list_concat(['<http://eulersharp.sourceforge.net/2003/03swap/prolog#', Y, '>'], Z),\n wt(Z)\n ; wg(X)\n ).\n\nwk([]) :-\n !.\nwk([X|Y]) :-\n write(', '),\n wt(X),\n wk(Y).\n\nwl([]) :-\n !.\nwl([X|Y]) :-\n write(' '),\n wg(X),\n wl(Y).\n\nwq([],_) :-\n !.\nwq([X|Y],allv) :-\n !,\n write('@forAll '),\n wt(X),\n wk(Y),\n write('. ').\nwq([X|Y],some) :-\n ( \\+flag('no-qvars')\n -> write('@forSome '),\n wt(X),\n wk(Y),\n write('. ')\n ; true\n ).\n\nwb([]) :-\n !.\nwb([X = Y|Z]) :-\n wp('<http://www.w3.org/2000/10/swap/reason#binding>'),\n write(' [ '),\n wp('<http://www.w3.org/2000/10/swap/reason#variable>'),\n write(' '),\n wv(X),\n write('; '),\n wp('<http://www.w3.org/2000/10/swap/reason#boundTo>'),\n write(' '),\n wv(Y),\n write('];'),\n nl,\n indent,\n wb(Z).\n\nwv(X) :-\n atom(X),\n atom_concat(avar, Y, X),\n !,\n write('[ '),\n wp('<http://www.w3.org/2004/06/rei#uri>'),\n write(' \"http://eyereasoner.github.io/var#x_'),\n write(Y),\n write('\"]').\nwv(X) :-\n atom(X),\n atom_concat(some, Y, X),\n !,\n write('[ '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Existential>'),\n write('; '),\n wp('<http://www.w3.org/2004/06/rei#nodeId>'),\n write(' \"_:sk_'),\n write(Y),\n write('\"]').\nwv(X) :-\n atom(X),\n nb_getval(var_ns, Sns),\n sub_atom(X, 1, I, _, Sns),\n !,\n write('[ '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Existential>'),\n write('; '),\n wp('<http://www.w3.org/2004/06/rei#nodeId>'),\n write(' \"'),\n write(Sns),\n J is I+1,\n sub_atom(X, J, _, 1, Q),\n write(Q),\n write('\"]').\nwv(X) :-\n atom(X),\n sub_atom(X, 1, _, 1, U),\n atomic_list_concat(['<', U, '>'], X),\n !,\n write('[ '),\n wp('<http://www.w3.org/2004/06/rei#uri>'),\n write(' \"'),\n write(U),\n write('\"]').\nwv(X) :-\n wg(X).\n\nws((X, Y)) :-\n !,\n conj_list((X, Y), Z),\n last(Z, U),\n ws(U).\nws(X) :-\n X =.. Y,\n last(Y, Z),\n ( \\+number(Z),\n Z \\= rdiv(_, _)\n -> true\n ; write(' ')\n ).\n\nwst :-\n findall([Key, Str],\n ( '<http://www.w3.org/2000/10/swap/log#outputString>'(Key, Str)\n ; answer(A1, A2, A3),\n djiti_answer(answer('<http://www.w3.org/2000/10/swap/log#outputString>'(Key, Str)), answer(A1, A2, A3))\n ),\n KS\n ),\n sort(KS, KT),\n forall(\n ( member([_, MT], KT),\n getcodes(MT, LT)\n ),\n ( escape_string(NT, LT),\n atom_codes(ST, NT),\n wt(ST)\n )\n ),\n ( catch(nb_getval(csv_header, Header), _, Header = []),\n wct(Header, Header),\n length(Header, Headerl),\n query(Where, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>'(_, Select)),\n catch(call(Where), _, fail),\n write('\\r\\n'),\n wct(Select, Header),\n cnt(output_statements, Headerl),\n cnt(answer_count),\n nb_getval(answer_count, AnswerCount),\n ( flag('limited-answer', AnswerLimit),\n AnswerCount >= AnswerLimit\n -> true\n ; fail\n )\n ; true\n ).\n\nwct([], []) :-\n !.\nwct([A], [C]) :-\n !,\n wcf(A, C).\nwct([A|B], [C|D]) :-\n wcf(A, C),\n ( flag('csv-separator', S)\n -> true\n ; S = ','\n ),\n write(S),\n wct(B, D).\n\nwcf(A, _) :-\n var(A),\n !.\nwcf(rdiv(X, Y), _) :-\n number_codes(Y, [0'1|Z]),\n lzero(Z, Z),\n !,\n ( Z = []\n -> F = '~d.0'\n ; length(Z, N),\n number_codes(X, U),\n ( length(U, N)\n -> F = '0.~d'\n ; atomic_list_concat(['~', N, 'd'], F)\n )\n ),\n format(F, [X]).\nwcf(literal(A, B), _) :-\n !,\n atom_codes(A, C),\n subst([[[0'\\\\, 0'\"], [0'\", 0'\"]]], C, E),\n atom_codes(F, E),\n ( B \\= type('<http://www.w3.org/2001/XMLSchema#dateTime>'),\n B \\= type('<http://www.w3.org/2001/XMLSchema#date>'),\n B \\= type('<http://www.w3.org/2001/XMLSchema#time>'),\n B \\= type('<http://www.w3.org/2001/XMLSchema#duration>'),\n B \\= type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'),\n B \\= type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')\n -> write('\"'),\n write(F),\n write('\"')\n ; write(F)\n ).\nwcf(A, _) :-\n atom(A),\n nb_getval(var_ns, Sns),\n sub_atom(A, 1, I, _, Sns),\n !,\n J is I+1,\n sub_atom(A, J, _, 1, B),\n write('_:'),\n write(B).\nwcf(A, _) :-\n atom(A),\n flag('quantify', Prefix),\n sub_atom(A, 1, _, _, Prefix),\n !,\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(B, ['quantify', Prefix, A]),\n wt0(B).\nwcf(A, B) :-\n atom(A),\n relabel(A, C),\n sub_atom(C, 0, 1, _, '<'),\n sub_atom(C, _, 1, 0, '>'),\n !,\n sub_atom(C, 1, _, 1, D),\n ( sub_atom(B, _, 2, 0, 'ID')\n -> ( flag('hmac-key', Key)\n -> hmac_sha(Key, D, E, [algorithm(sha1)])\n ; sha_hash(D, E, [algorithm(sha1)])\n ),\n atom_codes(F, E),\n base64xml(F, G),\n write(G)\n ; write(D)\n ).\nwcf(A, _) :-\n atom(A),\n sub_atom(A, 0, 1, _, '_'),\n !,\n sub_atom(A, 1, _, 0, B),\n write(B).\nwcf(A, _) :-\n with_output_to(atom(B), wg(A)),\n write(B).\n\nindent:-\n nb_getval(indentation, A),\n tab(A).\n\nindentation(C) :-\n nb_getval(indentation, A),\n B is A+C,\n nb_setval(indentation, B).\n\n\n% ----------------------------\n% EAM (Euler Abstract Machine)\n% ----------------------------\n%\n% In a nutshell:\n%\n% 1/ Select rule P => C\n% 2/ Prove P & NOT(C) (backward chaining) and if it fails backtrack to 1/\n% 3/ If P & NOT(C) assert C (forward chaining) and remove brake\n% 4/ If C = answer(A) and tactic limited-answer stop, else backtrack to 2/\n% 5/ If brake or tactic linear-select stop, else start again at 1/\n%\n\neam(Span) :-\n ( cnt(tr),\n ( flag(debug)\n -> format(user_error, 'eam/1 entering span ~w~n', [Span]),\n flush_output(user_error)\n ; true\n ),\n ( flag('max-inferences', MaxInf),\n statistics(inferences, Inf),\n Inf > MaxInf\n -> throw(max_inferences_exceeded(MaxInf))\n ; true\n ),\n implies(Prem, Conc, Src),\n ignore(Prem = true),\n ( flag(nope),\n \\+flag('rule-histogram')\n -> true\n ; copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(Prem, Conc), Rule)\n ),\n ( flag(debug)\n -> format(user_error, '. eam/1 selecting rule ~q~n', [implies(Prem, Conc, Src)]),\n flush_output(user_error)\n ; true\n ),\n ( flag('no-ucall')\n -> catch(call_residue_vars(call(Prem), []), Exc,\n ( Exc = error(existence_error(procedure, _), _)\n -> fail\n ; throw(Exc)\n )\n )\n ; catch(call_residue_vars(ucall(Prem), []), Exc,\n ( Exc = error(existence_error(procedure, _), _)\n -> fail\n ; throw(Exc)\n )\n )\n ),\n ( ( Conc = false\n ; Conc = answer(false, void, void)\n )\n -> with_output_to(atom(PN3), wt('<http://www.w3.org/2000/10/swap/log#implies>'(Prem, false))),\n ( flag('ignore-inference-fuse')\n -> format(user_error, '** ERROR ** eam ** ~w~n', [inference_fuse(PN3)]),\n fail\n ; throw(inference_fuse(PN3))\n )\n ; true\n ),\n \\+atom(Conc),\n ( flag('rule-histogram'),\n copy_term_nat(Rule, RuleL)\n -> lookup(RTP, tp, RuleL),\n catch(cnt(RTP), _, nb_setval(RTP, 0))\n ; true\n ),\n cnt(tp),\n djiti_conc(Conc, Concd),\n ( Concd = ':-'(Head, Body)\n -> \\+clause(Head, Body)\n ; ( Concd = '<http://www.w3.org/2000/10/swap/log#implies>'(_, _)\n -> copy_term_nat(Concd, Concc),\n labelvars(Concc, 0, _, avar),\n \\+cc(Concc),\n assertz(cc(Concc))\n ; ( flag('no-ucall')\n -> \\+catch(call(Concd), _, fail)\n ; \\+catch(ucall(Concd), _, fail)\n )\n )\n ),\n ( flag('rule-histogram')\n -> lookup(RTC, tc, RuleL),\n catch(cnt(RTC), _, nb_setval(RTC, 0))\n ; true\n ),\n ( Concd = (_, _),\n conj_list(Concd, Cl)\n -> length(Cl, Ci),\n cnt(tc, Ci)\n ; cnt(tc)\n ),\n ( Concd \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(_, _),\n Concd \\= ':-'(_, _)\n -> nb_getval(wn, W),\n labelvars(Prem-Concd, W, N), % failing when Prem contains attributed variables\n nb_setval(wn, N)\n ; true\n ),\n ( flag(debug)\n -> format(user_error, '... eam/1 assert step ~q~n', [Concd]),\n flush_output(user_error)\n ; true\n ),\n conj_list(Concd, La),\n couple(La, La, Lc),\n findall([D, F],\n ( member([D, D], Lc),\n unify(D, F),\n ( F = '<http://www.w3.org/2000/10/swap/log#implies>'(_, _)\n -> true\n ; catch(\\+F, _, true)\n )\n ),\n Ld\n ),\n couple(Ls, Le, Ld),\n conj_list(Concs, Ls),\n conj_list(Conce, Le),\n astep(Src, Prem, Concd, Conce, Rule),\n ( ( Concs = answer(_, _, _)\n ; Concs = (answer(_, _, _), _)\n )\n -> cnt(answer_count)\n ; true\n ),\n nb_getval(answer_count, AnswerCount),\n ( flag('limited-answer', AnswerLimit),\n AnswerCount >= AnswerLimit\n -> ( flag(strings)\n -> true\n ; w3\n )\n ; retract(brake),\n fail\n )\n ; ( brake\n ; flag(tactic, 'linear-select')\n ),\n ( S is Span+1,\n ( \\+span(S)\n -> assertz(span(S))\n ; true\n ),\n nb_getval(limit, Limit),\n Span < Limit,\n eam(S)\n ; \\+flag('multi-query'),\n \\+got_models,\n forall(\n modelo(Mz, Mn, Ml),\n retract(model(Mz, Mn, Ml))\n ),\n ( flag('debug-models')\n -> mf(model(_, _, _))\n ; true\n ),\n ( model(Mx, _, _),\n findall(My,\n ( model(Mx, _, My)\n ),\n Mq\n ),\n Mq = [Mh|Mt],\n findall(Me,\n ( member(Me, Mh),\n forall(\n member(Mm, Mt),\n member(Me, Mm)\n ),\n ( \\+Me\n -> djiti_assertz(Me)\n ; true\n )\n ),\n _\n ),\n fail\n ; true\n ),\n assertz(got_models),\n eam(Span)\n ; ( flag(strings)\n -> true\n ; w3\n )\n ; true\n ),\n !\n ; assertz(brake),\n exogen,\n eam(Span)\n ).\n\nastep(A, B, Cd, Cn, Rule) :- % astep(Source, Premise, Conclusion, Conclusion_unique, Rule)\n ( Cn = (Dn, En)\n -> functor(Dn, P, N),\n ( \\+pred(P),\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>',\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>',\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>',\n P \\= '<http://www.w3.org/2000/10/swap/log#implies>',\n P \\= '<http://www.w3.org/2000/10/swap/log#callWithCleanup>',\n N = 2\n -> assertz(pred(P))\n ; true\n ),\n ( Dn \\= '<http://www.w3.org/2000/10/swap/log#implies>'(_, _),\n catch(call(Dn), _, fail)\n -> true\n ; djiti_assertz(Dn),\n ( flag('pass-only-new'),\n Dn \\= answer(_, _, _),\n \\+pass_only_new(Dn)\n -> assertz(pass_only_new(Dn))\n ; true\n ),\n ( flag(nope)\n -> true\n ; ( B = '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(P1, Q1),\n Rule = '<http://www.w3.org/2000/10/swap/log#implies>'(Q6, R6),\n prfstep('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(P1, Q1), Q3, Q4, _,\n '<http://www.w3.org/2000/10/swap/log#implies>'(P6, Q6), forward, A)\n -> assertz(prfstep(Dn, Q3, Q4, Cd, '<http://www.w3.org/2000/10/swap/log#implies>'(P6, R6), forward, A))\n ; term_index(B, Pnd),\n assertz(prfstep(Dn, B, Pnd, Cd, Rule, forward, A))\n )\n )\n ),\n astep(A, B, Cd, En, Rule)\n ; ( Cn = true\n -> true\n ; functor(Cn, P, N),\n ( \\+pred(P),\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>',\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>',\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>',\n P \\= '<http://www.w3.org/2000/10/swap/log#callWithCleanup>',\n P \\= '<http://www.w3.org/2000/10/swap/log#implies>',\n N = 2\n -> assertz(pred(P))\n ; true\n ),\n ( Cn \\= '<http://www.w3.org/2000/10/swap/log#implies>'(_, _),\n catch(call(Cn), _, fail)\n -> true\n ; djiti_assertz(Cn),\n ( flag('pass-only-new'),\n Cn \\= answer(_, _, _),\n \\+pass_only_new(Cn)\n -> assertz(pass_only_new(Cn))\n ; true\n ),\n ( flag(nope)\n -> true\n ; ( B = '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(P1, Q1),\n Rule = '<http://www.w3.org/2000/10/swap/log#implies>'(Q6, R6),\n prfstep('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(P1, Q1), Q3, Q4, _,\n '<http://www.w3.org/2000/10/swap/log#implies>'(P6, Q6), forward, A)\n -> assertz(prfstep(Cn, Q3, Q4, Cd, '<http://www.w3.org/2000/10/swap/log#implies>'(P6, R6), forward, A))\n ; term_index(B, Pnd),\n assertz(prfstep(Cn, B, Pnd, Cd, Rule, forward, A))\n )\n )\n )\n )\n ).\n\nistep(Src, Prem, Conc, Rule) :- % istep(Source, Premise, Conclusion, Rule)\n copy_term_nat(Prem, Prec),\n labelvars(Prec, 0, _),\n term_index(Prec, Pnd),\n ( \\+prfstep(Conc, Prec, Pnd, Conc, Rule, backward, Src)\n -> assertz(prfstep(Conc, Prec, Pnd, Conc, Rule, backward, Src))\n ; true\n ).\n\npstep(Rule) :-\n copy_term_nat(Rule, RuleL),\n lookup(RTC, tc, RuleL),\n catch(cnt(RTC), _, nb_setval(RTC, 0)),\n lookup(RTP, tp, RuleL),\n catch(cnt(RTP), _, nb_setval(RTP, 0)).\n\nhstep(A, B) :-\n ( nonvar(A),\n A = exopred(P, S, O)\n -> pred(P),\n U =.. [P, S, O],\n qstep(U, B)\n ; qstep(A, B)\n ).\n\nqstep(A, B) :-\n prfstep(A, B, _, _, _, _, _).\nqstep(A, true) :-\n ( nonvar(A)\n -> ( A =.. [P, [S1, S2|S3], O]\n -> B =.. [P, S1, S2, S3, O]\n ; ( A =.. [P, S, literal(O1, O2)]\n -> B =.. [P, S, O1, O2]\n ; B = A\n )\n )\n ; pred(P),\n A =.. [P, _, _],\n B = A\n ),\n catch(clause(B, true), _, fail),\n \\+prfstep(A, _, _, _, _, _, _).\n\n%\n% DJITI (Deep Just In Time Indexing)\n%\n\ndjiti_answer(answer((A, B)), (C, D)) :-\n !,\n djiti_answer(answer(A), C),\n djiti_answer(answer(B), D).\ndjiti_answer(answer(A), answer(P, S, O)) :-\n ( nonvar(A)\n ; atom(P),\n S \\= void\n ),\n A =.. [P, S, O],\n !.\ndjiti_answer(answer(exopred(P, S, O)), answer(P, S, O)) :-\n ( var(S)\n ; S \\= void\n ),\n !.\ndjiti_answer(answer(A), answer(A, void, void)) :-\n !.\ndjiti_answer(A, A).\n\ndjiti_conc(':-'(exopred(P, S, O), B), ':-'(A, B)) :-\n !,\n A =.. [P, S, O].\ndjiti_conc(answer((A, B), void, void), (answer(A, void, void), D)) :-\n !,\n djiti_conc(answer(B, void, void), D).\ndjiti_conc(A, A).\n\ndjiti_fact(answer(P, S, O), answer(P, S, O)) :-\n atomic(P),\n !,\n ( P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>',\n P \\= '<http://www.w3.org/2000/10/swap/log#callWithCleanup>',\n \\+pred(P)\n -> assertz(pred(P))\n ; true\n ).\ndjiti_fact(implies(A, B, C), implies(A, B, C)) :-\n nonvar(B),\n conj_list(B, D),\n forall(\n member(E, D),\n ( unify(E, F),\n F =.. [P, _, _],\n ( \\+fpred(P)\n -> assertz(fpred(P))\n ; true\n )\n )\n ),\n !.\ndjiti_fact('<http://www.w3.org/2000/10/swap/log#implies>'(A, B), C) :-\n nonvar(B),\n ( conj_list(B, D)\n -> true\n ; D = B\n ),\n forall(\n member(E, D),\n ( unify(E, F),\n ( F =.. [P, _, _],\n \\+fpred(P)\n -> assertz(fpred(P))\n ; true\n )\n )\n ),\n !,\n ( retwist(A, B, Z)\n -> true\n ; Z = '<>'\n ),\n makevars(implies(A, B, Z), C, zeta).\ndjiti_fact(':-'(A, B), ':-'(C, D)) :-\n !,\n makevars((A, B), (C, E), eta),\n copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(E, C), F),\n ( flag(nope)\n -> D = E\n ; retwist(E, C, G),\n ( E = when(H, I)\n -> conj_append(I, istep(G, E, C, F), J),\n D = when(H, J)\n ; conj_append(E, istep(G, E, C, F), D)\n )\n ).\ndjiti_fact('<http://www.w3.org/2000/10/swap/log#dcg>'(_, literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))), B) :-\n !,\n read_term_from_atom(A, C, []),\n dcg_translate_rule(C, B).\ndjiti_fact('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(A, B), ':-'('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(A, B), true)) :-\n !.\ndjiti_fact(A, A) :-\n ground(A),\n A =.. [P, _, _],\n ( P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>',\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>',\n P \\= '<http://www.w3.org/2000/10/swap/log#callWithCleanup>',\n P \\= query,\n P \\= pfx,\n P \\= flag,\n P \\= semantics,\n \\+pred(P)\n -> assertz(pred(P))\n ; true\n ),\n !.\ndjiti_fact(A, A).\n\ndjiti_assertz(A) :-\n djiti_fact(A, B),\n assertz(B).\n\n%\n% Built-ins\n%\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#avg>'(A, B) :-\n \\+flag(restricted),\n avg(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#becomes>'(A, B) :-\n \\+flag(restricted),\n catch(call(A), _, fail),\n A \\= B,\n unify(A, C),\n conj_list(C, D),\n forall(\n member(E, D),\n ( ( E = '<http://www.w3.org/2000/10/swap/log#implies>'(Prem, Conc)\n -> retract(implies(Prem, Conc, Src)),\n assertz(retwist(Prem, Conc, Src))\n ; ( E = ':-'(Ci, Pi),\n Pi \\= true\n -> ( flag(nope)\n -> Ph = Pi\n ; ( Pi = when(Ai, Bi)\n -> conj_append(Bi, istep(Si, Pi, Ci, _), Bh),\n Ph = when(Ai, Bh)\n ; conj_append(Pi, istep(Si, Pi, Ci, _), Ph)\n ),\n ':-'(Ci, Ph),\n assertz(retwist(Pi, Ci, Si))\n ),\n retract(':-'(Ci, Ph))\n ; E \\= ':-'(_, true),\n retract(E)\n )\n ),\n djiti_answer(answer(E), Z),\n retractall(Z),\n ( flag('pass-only-new'),\n pass_only_new(E)\n -> retract(pass_only_new(E))\n ; true\n )\n )\n ),\n nb_getval(wn, W),\n labelvars(B, W, N),\n nb_setval(wn, N),\n unify(B, F),\n conj_list(F, G),\n forall(\n member(H, G),\n ( djiti_assertz(H),\n ( flag('pass-only-new'),\n \\+pass_only_new(H)\n -> assertz(pass_only_new(H))\n ; true\n )\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#before>'(A, B) :-\n \\+flag(restricted),\n A,\n B.\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#biconditional>'(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, B)|C], D) :-\n \\+flag(restricted),\n within_scope(_),\n ( nb_getval(bnet, done)\n -> true\n ; bnet,\n nb_setval(bnet, done)\n ),\n bvar(A),\n bval(B),\n bcon(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, B)], C, D).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#binaryEntropy>'(A, B) :-\n \\+flag(restricted),\n getnumber(A, C),\n ( C =:= 0.0\n -> B is 0.0\n ; ( C =:= 1.0\n -> B is 0.0\n ; B is -(C*log(C)+(1-C)*log(1-C))/log(2)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#calculate>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], C) :-\n \\+flag(restricted),\n findall(U,\n ( member(V, B),\n getnumber(V, U)\n ),\n W\n ),\n read_term_from_atom(A, D, [variables(W)]),\n catch(C is D, _, fail).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#call>'(A, B) :-\n \\+flag(restricted),\n nonvar(A),\n A \\= [_,_],\n !,\n when(\n ( nonvar(B)\n ),\n ( reset_gensym,\n tmp_file(Tmp1),\n open(Tmp1, write, Ws1, [encoding(utf8)]),\n tell(Ws1),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(C, D),\n format('@prefix ~w ~w.~n', [C, D])\n ),\n nl\n ),\n labelvars(A, 0, _),\n wt(A),\n write('.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp2),\n open(Tmp2, write, Ws2, [encoding(utf8)]),\n tell(Ws2),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(E, F),\n format('@prefix ~w ~w.~n', [E, F])\n ),\n nl\n ),\n labelvars(B, 0, _),\n write('{'),\n wt(B),\n write('} => {'),\n wt(B),\n write('}.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp3),\n !,\n ( current_prolog_flag(windows, true)\n -> A1 = ['cmd.exe', '/C']\n ; A1 = []\n ),\n ( current_prolog_flag(argv, Argv),\n append(Argu, ['--'|_], Argv)\n -> append(Argu, ['--'], A2)\n ; A2 = ['eye']\n ),\n ( flag(blogic)\n -> A3 = ['--blogic']\n ; A3 = ['']\n ),\n append([A1, A2, ['--nope', A3, Tmp1, '--query', Tmp2, '>', Tmp3]], A4),\n findall([G, ' '],\n ( member(G, A4)\n ),\n H\n ),\n flatten(H, I),\n atomic_list_concat(I, J),\n ( catch(exec(J, _), _, fail)\n -> n3_n3p(Tmp3, semantics),\n absolute_uri(Tmp3, Tmp),\n atomic_list_concat(['<', Tmp, '>'], Res),\n semantics(Res, L),\n delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n L \\= []\n ; delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n fail\n )\n )\n ).\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#call>'(Sc, A) :-\n \\+flag(restricted),\n within_scope(Sc),\n nonvar(A),\n conjify(A, B),\n catch(call(B), _, fail),\n ( flag(nope)\n -> true\n ; copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(B, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#call>'(Sc, B)), C),\n istep('<>', B, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#call>'(Sc, B), C)\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#cartesianProduct>'(A, B) :-\n \\+flag(restricted),\n findall(C,\n ( cartesian(A, C)\n ),\n B\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#closure>'(Sc, A) :-\n \\+flag(restricted),\n within_scope(Sc),\n hstep(A, _).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#compoundTerm>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], C) :-\n \\+flag(restricted),\n atomify(B, D),\n read_term_from_atom(A, C, [variables(D)]).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#cov>'(A, B) :-\n \\+flag(restricted),\n cov(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'(A, B) :-\n \\+flag(restricted),\n atomify(A, C),\n D =.. C,\n ( B = true\n -> catch(call(D), _, fail)\n ; \\+catch(call(D), _, fail)\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#exec>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( exec(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#fail>'(A, B) :-\n \\+flag(restricted),\n nonvar(A),\n A \\= [_,_],\n !,\n when(\n ( nonvar(B)\n ),\n ( reset_gensym,\n tmp_file(Tmp1),\n open(Tmp1, write, Ws1, [encoding(utf8)]),\n tell(Ws1),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(C, D),\n format('@prefix ~w ~w.~n', [C, D])\n ),\n nl\n ),\n labelvars(A, 0, _),\n wt(A),\n write('.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp2),\n open(Tmp2, write, Ws2, [encoding(utf8)]),\n tell(Ws2),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(E, F),\n format('@prefix ~w ~w.~n', [E, F])\n ),\n nl\n ),\n labelvars(B, 0, _),\n write('{'),\n wt(B),\n write('} => {'),\n wt(B),\n write('}.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp3),\n !,\n ( current_prolog_flag(windows, true)\n -> A1 = ['cmd.exe', '/C']\n ; A1 = []\n ),\n ( current_prolog_flag(argv, Argv),\n append(Argu, ['--'|_], Argv)\n -> append(Argu, ['--'], A2)\n ; A2 = ['eye']\n ),\n ( flag(blogic)\n -> A3 = ['--blogic']\n ; A3 = ['']\n ),\n append([A1, A2, ['--nope', A3, Tmp1, '--query', Tmp2, '>', Tmp3]], A4),\n findall([G, ' '],\n ( member(G, A4)\n ),\n H\n ),\n flatten(H, I),\n atomic_list_concat(I, J),\n ( catch(exec(J, _), _, fail)\n -> n3_n3p(Tmp3, semantics),\n absolute_uri(Tmp3, Tmp),\n atomic_list_concat(['<', Tmp, '>'], Res),\n semantics(Res, L),\n delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n L = []\n ; delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n fail\n )\n )\n ).\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#fail>'(A, B) :-\n \\+flag(restricted),\n within_scope(A),\n \\+catch(call(B), _, fail).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#fileString>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n read_file_to_string(A, C, []),\n ( string_concat(D, \"\\n\", C)\n -> true\n ; D = C\n ),\n atom_string(B, D).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>'(A, B) :-\n \\+flag(restricted),\n call_cleanup(A, B),\n ( flag(nope)\n -> true\n ; conj_append(A, B, C),\n copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(C, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>'(A, B)), D),\n istep('<>', C, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>'(A, B), D)\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(A, B) :-\n \\+flag(restricted),\n nonvar(A),\n A \\= [_,_],\n !,\n when(\n ( nonvar(B)\n ),\n ( reset_gensym,\n tmp_file(Tmp1),\n open(Tmp1, write, Ws1, [encoding(utf8)]),\n tell(Ws1),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(C, D),\n format('@prefix ~w ~w.~n', [C, D])\n ),\n nl\n ),\n labelvars(A, 0, _),\n wt(A),\n write('.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp2),\n open(Tmp2, write, Ws2, [encoding(utf8)]),\n tell(Ws2),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(E, F),\n format('@prefix ~w ~w.~n', [E, F])\n ),\n nl\n ),\n write('{'),\n wt('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(_, B)),\n write('} => {'),\n wt('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(_, B)),\n write('}.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp3),\n !,\n ( current_prolog_flag(windows, true)\n -> A1 = ['cmd.exe', '/C']\n ; A1 = []\n ),\n ( current_prolog_flag(argv, Argv),\n append(Argu, ['--'|_], Argv)\n -> append(Argu, ['--'], A2)\n ; A2 = ['eye']\n ),\n ( flag(blogic)\n -> A3 = ['--blogic']\n ; A3 = ['']\n ),\n append([A1, A2, ['--nope', A3, Tmp1, '--query', Tmp2, '>', Tmp3]], A4),\n findall([G, ' '],\n ( member(G, A4)\n ),\n H\n ),\n flatten(H, I),\n atomic_list_concat(I, J),\n ( catch(exec(J, _), _, fail)\n -> n3_n3p(Tmp3, semantics),\n absolute_uri(Tmp3, Tmp),\n atomic_list_concat(['<', Tmp, '>'], Res),\n semantics(Res, L),\n conj_list(K, L),\n labelvars(K, 0, _),\n B = [_, _, M],\n K = '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(_, [_, _, M]),\n delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3)\n ; delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n fail\n )\n )\n ).\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(Sc, [A, B, C]) :-\n \\+flag(restricted),\n within_scope(Sc),\n nonvar(B),\n \\+is_list(B),\n catch(findall(A, B, E), _, E = []),\n ( flag(warn)\n -> copy_term_nat([A, B, E], [Ac, Bc, Ec]),\n labelvars([Ac, Bc, Ec], 0, _),\n ( fact('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(Sc, [Ac, Bc, G]))\n -> ( E \\= G\n -> format(user_error, '** WARNING ** conflicting_findall_answers ~w VERSUS ~w~n', [[A, B, G], [A, B, E]]),\n flush_output(user_error)\n ; true\n )\n ; assertz(fact('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(Sc, [Ac, Bc, Ec])))\n )\n ; true\n ),\n E = C.\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#firstRest>'([A|B], [A, B]) :-\n \\+flag(restricted).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#format>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, D),\n preformat(B, E),\n format_to_chars(D, E, F),\n atom_codes(C, F)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphCopy>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#labelvars>'(A, C),\n conj_list(C, L),\n sort(L, M),\n conj_list(K, M),\n unify(K, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphDifference>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( makevars(A, C, delta),\n difference(C, D),\n unify(D, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphIntersection>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( intersect(A, M),\n unify(M, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphList>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( unify(A, C),\n conj_list(C, D),\n ( nonvar(B)\n -> cflat(B, E),\n ( ground(E)\n -> distinct(E, D)\n ; D = E\n )\n ; ( ground(D)\n -> distinct(D, B)\n ; B = D\n )\n )\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphMember>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( conj_list(A, C),\n member(D, C),\n unify(D, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphPair>'((A, B), [A, B]) :-\n \\+flag(restricted).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#hmac-sha>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n flag('hmac-key', Key),\n hmac_sha(Key, A, C, [algorithm(sha1)]),\n atom_codes(D, C),\n base64xml(D, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#ignore>'(Sc, A) :-\n \\+flag(restricted),\n within_scope(Sc),\n nonvar(A),\n ( catch(call(A), _, fail)\n -> ( flag(nope)\n -> true\n ; copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#ignore>'(Sc, A)), R),\n istep('<>', A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#ignore>'(Sc, A), R)\n )\n ; true\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#label>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( atom(A),\n ( sub_atom(A, _, 19, _, '/.well-known/genid/')\n -> ( sub_atom(A, I, 1, _, '#')\n -> J is I+1,\n sub_atom(A, J, _, 1, B)\n ; B = ''\n )\n ; atom_concat(some, C, A),\n atomic_list_concat(['sk_', C], B)\n )\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#labelvars>'(A, B) :-\n \\+flag(restricted),\n copy_term_nat(A, C),\n labelvars(C, 0, _),\n term_index(C, D),\n ( got_labelvars(C, D, B)\n -> true\n ; copy_term_nat(A, B),\n labelvars(B, 0, _, avar),\n assertz(got_labelvars(C, D, B))\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#length>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( ( getlist(A, C)\n -> true\n ; conj_list(A, D),\n ( ground(D)\n -> distinct(D, C)\n ; C = D\n )\n ),\n length(C, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#match>'(_, B) :-\n \\+flag(restricted),\n \\+ \\+catch(call(B), _, fail).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#max>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( bmax(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#min>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( bmin(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#multisetEqualTo>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n nonvar(B)\n ),\n ( sort(0, @=<, A, C),\n sort(0, @=<, B, C)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#multisetNotEqualTo>'(A, B) :-\n \\+flag(restricted),\n \\+'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#multisetEqualTo>'(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#notLabel>'(A, B) :-\n \\+flag(restricted),\n \\+'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#label>'(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#numeral>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( getnumber(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#optional>'(Sc, A) :-\n \\+flag(restricted),\n within_scope(Sc),\n nonvar(A),\n ( \\+catch(call(A), _, fail)\n -> true\n ; catch(call(A), _, fail),\n ( flag(nope)\n -> true\n ; copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#optional>'(Sc, A)), R),\n istep('<>', A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#optional>'(Sc, A), R)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#pcc>'([A, B], C) :-\n \\+flag(restricted),\n pcc([A, B], C).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#prefix>'(Sc, literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n within_scope(Sc),\n with_output_to_codes(wh, C),\n atom_codes(A, C),\n retractall(wpfx(_)).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#propertyChainExtension>'([A], [B, C]) :-\n \\+flag(restricted),\n !,\n D =.. [A, B, C],\n catch(call(D), _, fail).\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#propertyChainExtension>'([A|B], [C, D]) :-\n \\+flag(restricted),\n E =.. [A, C, F],\n catch(call(E), _, fail),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#propertyChainExtension>'(B, [F, D]).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#random>'([A|B], C) :-\n \\+flag(restricted),\n term_index([A|B], I),\n ( B \\= [],\n got_random([A|B], I, C)\n -> true\n ; catch(nb_getval(random, D), _, D = 16127),\n E is mod(1046527*D+16769023, 1073676287),\n nb_setval(random, E),\n C is mod(E, A),\n ( B \\= []\n -> assertz(got_random([A|B], I, C))\n ; true\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#reverse>'(A, B) :-\n \\+flag(restricted),\n reverse(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#rms>'(A, B) :-\n \\+flag(restricted),\n rms(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#roc>'(St, [Sen, Asp]) :-\n \\+flag(restricted),\n getnumber(St, K),\n ( getnumber(Sen, S)\n -> Asp is 1-(1-exp(-K*(S-1)))*(1+exp(K))/(1+exp(-K*(S-1)))/(1-exp(K))\n ; getnumber(Asp, A),\n Sen is (1-exp(-K*A))*(1+exp(-K))/(1+exp(-K*A))/(1-exp(-K))\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#sha>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n sha_hash(A, C, [algorithm(sha1)]),\n atom_codes(D, C),\n base64xml(D, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#sigmoid>'(A, B) :-\n \\+flag(restricted),\n getnumber(A, C),\n B is 1/(1+exp(-C)).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#skolem>'(X, Y) :-\n \\+flag(restricted),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(Y, X),\n ( \\+keep_skolem(Y)\n -> assertz(keep_skolem(Y))\n ; true\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#sort>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( sort(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#std>'(A, B) :-\n \\+flag(restricted),\n std(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#stringEscape>'(literal(X, Y), literal(Z, Y)) :-\n \\+flag(restricted),\n when(\n ( ground(X)\n ),\n ( atom_codes(X, U),\n escape_string(U, V),\n atom_codes(Z, V)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#stringReverse>'(literal(X, Y), literal(Z, Y)) :-\n \\+flag(restricted),\n when(\n ( ground(X)\n ),\n ( atom_codes(X, U),\n reverse(U, V),\n atom_codes(Z, V)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#stringSplit>'([literal(X, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))],\n Z) :-\n \\+flag(restricted),\n when(\n ( ground([X, Y])\n ),\n ( atom_codes(X, U),\n atom_codes(Y, C),\n ( C = []\n -> findall(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')),\n ( member(B, U),\n atom_codes(A, [B])\n ),\n Z\n )\n ; escape_string(V, C),\n esplit_string(U, V, [], W),\n findall(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')),\n ( member(B, W),\n atom_codes(A, B)\n ),\n Z\n )\n )\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#subsequence>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( sub_list(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#trace>'(X, Y) :-\n \\+flag(restricted),\n tell(user_error),\n write('TRACE '),\n ( ( var(X)\n ; findvar(X, beta)\n )\n -> copy_term_nat(Y, Z),\n wg(Z)\n ; writeq(Y)\n ),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transpose>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( e_transpose(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tripleList>'(A, [B, C, D]) :-\n \\+flag(restricted),\n A =.. [C, B, D].\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(X, Y) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ; ground(Y)\n ),\n ( ( is_list(Y),\n length(Y, I),\n I < 8\n -> Z =.. [tuple, X|Y]\n ; Z = tuple(X, Y)\n ),\n ( call(Z)\n -> true\n ; var(X),\n nb_getval(tuple, M),\n N is M+1,\n nb_setval(tuple, N),\n atom_number(A, N),\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 't_', A, '>'], X),\n assertz(Z)\n )\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#unique>'(A, B) :-\n \\+flag(restricted),\n ( got_unique(A, B)\n -> fail\n ; assertz(got_unique(A, B))\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#whenGround>'(A, B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( findvars(A, C, delta),\n C \\= []\n -> true\n ; catch(call(B), _, A = B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#wwwFormEncode>'(X, literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( ( ground(X)\n -> ( number(X)\n -> atom_number(T, X)\n ; X = literal(T, _)\n ),\n www_form_encode(T, Z),\n atom_codes(Z, U),\n subst([[[0'%, 0'2, 0'0], [0'+]]], U, V),\n atom_codes(Y, V)\n ; www_form_encode(X, Y)\n )\n )\n ).\n\n'<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>'(X, Y) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( X = [Y|Z],\n nonvar(Z)\n )\n ),\n !.\n\n'<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'(X, []) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( X = [_]\n )\n ),\n !.\n'<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'(X, '<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>') :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( X = [_]\n )\n ),\n !.\n'<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'(X, Y) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( X = [_|Y]\n )\n ),\n !.\n\n'<http://www.w3.org/2000/10/swap/crypto#md5>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n (\n md5_hash(A, B, [])\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/crypto#sha>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n ( sha_hash(A, C, [algorithm(sha1)]),\n hash_atom(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/crypto#sha256>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n ( sha_hash(A, C, [algorithm(sha256)]),\n hash_atom(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/crypto#sha512>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n ( sha_hash(A, C, [algorithm(sha512)]),\n hash_atom(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/graph#difference>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( makevars(A, C, delta),\n difference(C, D),\n unify(D, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/graph#intersection>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( intersect(A, C),\n unify(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/graph#length>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( conj_list(A, D),\n ( ground(D)\n -> distinct(D, C)\n ; C = D\n ),\n length(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/graph#list>'(A, B) :-\n conj_list(A, B).\n\n'<http://www.w3.org/2000/10/swap/graph#member>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphMember>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/graph#union>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( conjoin(A, C),\n unify(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#append>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n ( member(D, C),\n var(D),\n var(B)\n -> true\n ; append(C, B)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#first>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n C = [B|D],\n nonvar(D)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#firstRest>'([A|B], [A, B]).\n\n'<http://www.w3.org/2000/10/swap/list#in>'(A, B) :-\n when(\n ( nonvar(B)\n ),\n ( getlist(B, C),\n member(A, C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#iterate>'(A, [B, C]) :-\n when(\n ( nonvar(A)\n ),\n ( nth0(B, A, C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#last>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n last(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#length>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( ( getlist(A, C)\n -> true\n ; conj_list(A, D),\n ( ground(D)\n -> distinct(D, C)\n ; C = D\n )\n ),\n length(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#map>'([A, B], C) :-\n when(\n ( nonvar(A),\n nonvar(B)\n ),\n ( getlist(A, D),\n findall(E,\n ( member(F, D),\n G =.. [B, F, E],\n G\n ),\n C\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#member>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n member(B, C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#memberAt>'([A, B], C) :-\n when(\n ( nonvar(A)\n ),\n ( nth0(B, A, C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#multisetEqualTo>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#multisetEqualTo>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/list#multisetNotEqualTo>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#multisetNotEqualTo>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/list#remove>'([A, B], C) :-\n when(\n ( nonvar(A),\n nonvar(B)\n ),\n ( findall(I,\n ( member(I, A),\n I \\= B\n ),\n C\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#removeAt>'([A, B], C) :-\n when(\n ( nonvar(A)\n ),\n ( nth0(B, A, D),\n findall(I,\n ( member(I, A),\n I \\= D\n ),\n C\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#removeDuplicates>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n list_to_set(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#rest>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n C = [_|B]\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#setEqualTo>'(A, B) :-\n when(\n ( nonvar(A),\n nonvar(B)\n ),\n ( getlist(A, C),\n getlist(B, D),\n sort(C, E),\n sort(D, E)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#setNotEqualTo>'(A, B) :-\n \\+'<http://www.w3.org/2000/10/swap/list#setEqualTo>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/list#unique>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( sort(A, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#becomes>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#becomes>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/log#bound>'(X, Y) :-\n ( nonvar(X)\n -> Y = true\n ; Y = false\n ).\n\n'<http://www.w3.org/2000/10/swap/log#callWithCleanup>'(A, B) :-\n call_cleanup(A, B),\n ( flag(nope)\n -> true\n ; conj_append(A, B, C),\n copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(C, '<http://www.w3.org/2000/10/swap/log#callWithCleanup>'(A, B)), D),\n istep('<>', C, '<http://www.w3.org/2000/10/swap/log#callWithCleanup>'(A, B), D)\n ).\n\n'<http://www.w3.org/2000/10/swap/log#collectAllIn>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(B, A).\n\n'<http://www.w3.org/2000/10/swap/log#conclusion>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( reset_gensym,\n tmp_file(Tmp1),\n open(Tmp1, write, Ws1, [encoding(utf8)]),\n tell(Ws1),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(C, D),\n format('@prefix ~w ~w.~n', [C, D])\n ),\n nl\n ),\n labelvars(A, 0, _),\n wt(A),\n write('.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp2),\n !,\n ( current_prolog_flag(windows, true)\n -> A1 = ['cmd.exe', '/C']\n ; A1 = []\n ),\n ( current_prolog_flag(argv, Argv),\n append(Argu, ['--'|_], Argv)\n -> append(Argu, ['--'], A2)\n ; A2 = ['eye']\n ),\n ( flag(blogic)\n -> A3 = ['--blogic']\n ; A3 = ['']\n ),\n append([A1, A2, ['--nope', A3, Tmp1, '--pass-all', '>', Tmp2]], A4),\n findall([G, ' '],\n ( member(G, A4)\n ),\n H\n ),\n flatten(H, I),\n atomic_list_concat(I, J),\n ( catch(exec(J, _), _, fail)\n -> n3_n3p(Tmp2, semantics),\n absolute_uri(Tmp2, Tmp),\n atomic_list_concat(['<', Tmp, '>'], Res),\n semantics(Res, L),\n conj_list(B, L),\n labelvars(B, 0, _),\n delete_file(Tmp1),\n delete_file(Tmp2)\n ; delete_file(Tmp1),\n delete_file(Tmp2),\n fail\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#conjunction>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( conjoin(A, M),\n unify(M, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#content>'(A, B) :-\n \\+flag(restricted),\n '<http://www.w3.org/2000/10/swap/log#semantics>'(A, C),\n '<http://www.w3.org/2000/10/swap/log#n3String>'(C, B).\n\n'<http://www.w3.org/2000/10/swap/log#dtlit>'([A, B], C) :-\n when(\n ( ground(A)\n ; nonvar(C)\n ),\n ( ground(A),\n ( var(B)\n -> ( member(B, ['<http://www.w3.org/2001/XMLSchema#integer>', '<http://www.w3.org/2001/XMLSchema#double>',\n '<http://www.w3.org/2001/XMLSchema#date>', '<http://www.w3.org/2001/XMLSchema#time>', '<http://www.w3.org/2001/XMLSchema#dateTime>',\n '<http://www.w3.org/2001/XMLSchema#yearMonthDuration>', '<http://www.w3.org/2001/XMLSchema#dayTimeDuration>', '<http://www.w3.org/2001/XMLSchema#duration>']),\n dtlit([A, B], C),\n getnumber(C, D),\n dtlit([_, B], D)\n -> true\n ; ( dtlit([A, '<http://www.w3.org/2001/XMLSchema#boolean>'], C),\n getbool(C, _),\n B = '<http://www.w3.org/2001/XMLSchema#boolean>'\n -> true\n ; B = '<http://www.w3.org/2001/XMLSchema#string>',\n C = A\n )\n )\n ; A = literal(E, _),\n ( B = prolog:atom\n -> C = E\n ; C = literal(E, type(B))\n ),\n !\n )\n ; nonvar(C),\n dtlit([A, B], C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#equalTo>'(X, Y) :-\n unify(X, Y).\n\n'<http://www.w3.org/2000/10/swap/log#forAllIn>'([A, B], Sc) :-\n within_scope(Sc),\n when(\n ( nonvar(A),\n nonvar(B)\n ),\n ( forall(A, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#hasPrefix>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( pfx(_, A)\n -> B = true\n ; B = false\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#ifThenElseIn>'(A, B) :-\n \\+flag(restricted),\n nonvar(B),\n B \\= [_,_],\n !,\n when(\n ( nonvar(A)\n ),\n ( reset_gensym,\n tmp_file(Tmp1),\n open(Tmp1, write, Ws1, [encoding(utf8)]),\n tell(Ws1),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(C, D),\n format('@prefix ~w ~w.~n', [C, D])\n ),\n nl\n ),\n labelvars(B, 0, _),\n wt(B),\n write('.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp2),\n open(Tmp2, write, Ws2, [encoding(utf8)]),\n tell(Ws2),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(E, F),\n format('@prefix ~w ~w.~n', [E, F])\n ),\n nl\n ),\n write('{'),\n wt('<http://www.w3.org/2000/10/swap/log#ifThenElseIn>'(A, _)),\n write('} => {'),\n wt('<http://www.w3.org/2000/10/swap/log#ifThenElseIn>'(A, _)),\n write('}.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp3),\n !,\n ( current_prolog_flag(windows, true)\n -> A1 = ['cmd.exe', '/C']\n ; A1 = []\n ),\n ( current_prolog_flag(argv, Argv),\n append(Argu, ['--'|_], Argv)\n -> append(Argu, ['--'], A2)\n ; A2 = ['eye']\n ),\n ( flag(blogic)\n -> A3 = ['--blogic']\n ; A3 = ['']\n ),\n append([A1, A2, ['--nope', A3, Tmp1, '--query', Tmp2, '>', Tmp3]], A4),\n findall([G, ' '],\n ( member(G, A4)\n ),\n H\n ),\n flatten(H, I),\n atomic_list_concat(I, J),\n ( catch(exec(J, _), _, fail)\n -> n3_n3p(Tmp3, semantics),\n absolute_uri(Tmp3, Tmp),\n atomic_list_concat(['<', Tmp, '>'], Res),\n semantics(Res, L),\n conj_list(K, L),\n labelvars(K, 0, _),\n A = M,\n K = '<http://www.w3.org/2000/10/swap/log#ifThenElseIn>'(M, _),\n delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3)\n ; delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n fail\n )\n )\n ).\n'<http://www.w3.org/2000/10/swap/log#ifThenElseIn>'([A, B, C], Sc) :-\n within_scope(Sc),\n when(\n ( nonvar(A),\n nonvar(B),\n nonvar(C)\n ),\n ( if_then_else(A, B, C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#implies>'(X, Y) :-\n implies(U, V, _),\n unify(U, X),\n unify(V, Y),\n ( commonvars(X, Y, [])\n -> labelvars(Y, 0, _, avar)\n ; true\n ),\n ( var(Y)\n -> true\n ; Y \\= answer(_, _, _),\n Y \\= (answer(_, _, _), _)\n ).\n\n'<http://www.w3.org/2000/10/swap/log#includes>'(X, Y) :-\n within_scope(X),\n !,\n when(\n ( nonvar(Y)\n ),\n ( Y\n )\n ).\n'<http://www.w3.org/2000/10/swap/log#includes>'(X, Y) :-\n when(\n ( nonvar(X),\n nonvar(Y)\n ),\n ( conj_list(X, A),\n conj_list(Y, B),\n includes(A, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#includesNotBind>'(X, Y) :-\n within_scope(X),\n !,\n when(\n ( nonvar(Y)\n ),\n ( \\+ \\+call(Y)\n )\n ).\n'<http://www.w3.org/2000/10/swap/log#includesNotBind>'(X, Y) :-\n when(\n ( nonvar(X),\n nonvar(Y)\n ),\n ( conj_list(X, A),\n conj_list(Y, B),\n \\+ \\+includes(A, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#inferences>'(A, B) :-\n '<http://www.w3.org/2000/10/swap/log#conclusion>'(A, C),\n ( nonvar(B)\n -> '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphIntersection>'([B,C], B)\n ; B = C\n ).\n\n'<http://www.w3.org/2000/10/swap/log#langlit>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(A, lang(B))).\n\n'<http://www.w3.org/2000/10/swap/log#localN3String>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n term_variables(A, V),\n labelvars([A, V], 0, _, avar),\n with_output_to_chars((wq(V, allv), wt(A)), E),\n escape_string(E, F),\n atom_codes(B, F).\n\n'<http://www.w3.org/2000/10/swap/log#localName>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n ( sub_atom(A, 1, _, 1, C),\n (\n sub_atom_last(C, _, 1, N, '#') ->\n sub_atom(C, _, N, 0, B)\n ;\n sub_atom_last(C, _, 1, N, '/') ->\n sub_atom(C, _, N, 0, B)\n ;\n sub_atom_last(C, _, 1, N, ':') ->\n sub_atom(C, _, N, 0, B)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#n3String>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n ( n3s(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>')))\n -> true\n ; retractall(wpfx(_)),\n with_output_to_chars(wh, C1),\n \\+ (C1 = [], \\+flag('no-qnames')),\n numbervars(A),\n with_output_to_chars(wt(A), C2),\n append(C1, C2, C),\n escape_string(C, D),\n atom_codes(B, D),\n assertz(n3s(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))))\n ).\n\n'<http://www.w3.org/2000/10/swap/log#namespace>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n ( sub_atom(A, 1, _, 1, C),\n (\n sub_atom_last(C, N, 1, _, '#') ->\n M is N+1,\n sub_atom(C, 0, M, _, B)\n ;\n sub_atom_last(C, N, 1, _, '/') ->\n M is N+1,\n sub_atom(C, 0, M, _, B)\n ;\n sub_atom_last(C, N, 1, _, ':') ->\n M is N+1,\n sub_atom(C, 0, M, _, B)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#notEqualTo>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#notIncludes>'(X, Y) :-\n ignore(within_scope(X)),\n \\+'<http://www.w3.org/2000/10/swap/log#includes>'(X, Y).\n\n'<http://www.w3.org/2000/10/swap/log#parsedAsN3>'(literal(A, _), B) :-\n atom_codes(A, C),\n escape_string(D, C),\n atom_codes(E, D),\n tmp_file(Tmp),\n open(Tmp, write, Ws, [encoding(utf8)]),\n tell(Ws),\n writef(E, []),\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n atomic_list_concat(['<file://', Tmp, '>'], F),\n '<http://www.w3.org/2000/10/swap/log#semantics>'(F, B).\n\n'<http://www.w3.org/2000/10/swap/log#phrase>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], C) :-\n read_term_from_atom(A, D, [variables(B)]),\n findall(E,\n ( member(literal(E, type('<http://www.w3.org/2001/XMLSchema#string>')), C)\n ),\n F\n ),\n phrase(D, F, []).\n\n'<http://www.w3.org/2000/10/swap/log#prefix>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ; nonvar(B)\n ),\n ( pfx(C, A),\n sub_atom(C, 0, _, 1, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#racine>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( sub_atom(A, 1, _, 1, C),\n sub_atom(C, N, 1, _, '#'),\n sub_atom(C, 0, N, _, D),\n atomic_list_concat(['<', D, '>'], B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#rawType>'(A, B) :-\n nonvar(A),\n raw_type(A, C),\n C = B.\n\n'<http://www.w3.org/2000/10/swap/log#repeat>'(A, B) :-\n C is A-1,\n between(0, C, B).\n\n'<http://www.w3.org/2000/10/swap/log#semantics>'(X, Y) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( ( semantics(X, L)\n -> conj_list(Y, L)\n ; sub_atom(X, 0, 1, _, '<'),\n sub_atom(X, _, 1, 0, '>'),\n sub_atom(X, 1, _, 1, Z),\n catch(\n n3_n3p(Z, semantics),\n Exc,\n ( format(user_error, '** ERROR ** ~w **~n', [Exc]),\n flush_output(user_error),\n fail\n )\n ),\n semantics(X, L),\n conj_list(Y, L)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#semanticsOrError>'(X, Y) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( ( semantics(X, L)\n -> conj_list(Y, L)\n ; sub_atom(X, 0, 1, _, '<'),\n sub_atom(X, _, 1, 0, '>'),\n sub_atom(X, 1, _, 1, Z),\n catch(\n n3_n3p(Z, semantics),\n Exc,\n assertz(semantics(X, [literal(Exc, type('<http://www.w3.org/2001/XMLSchema#string>'))]))\n ),\n semantics(X, L),\n conj_list(Y, L)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#skolem>'(X, Y) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(Y, X),\n ( \\+keep_skolem(Y)\n -> assertz(keep_skolem(Y))\n ; true\n ).\n\n'<http://www.w3.org/2000/10/swap/log#trace>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#trace>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/log#uri>'(X, Y) :-\n when(\n ( nonvar(X)\n ; nonvar(Y)\n ),\n ( atomic(X),\n ( atom_concat(some, V, X)\n -> nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'sk_', V, '>'], U)\n ; ( atom_concat(avar, V, X)\n -> atomic_list_concat(['<http://eyereasoner.github.io/var#x_', V, '>'], U)\n ; U = X\n )\n ),\n sub_atom(U, 1, _, 1, Z),\n atomic_list_concat(['<', Z, '>'], U),\n Y = literal(Z, type('<http://www.w3.org/2001/XMLSchema#string>')),\n !\n ; nonvar(Y),\n Y = literal(Z, type('<http://www.w3.org/2001/XMLSchema#string>')),\n atomic_list_concat(['<', Z, '>'], X)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#uuid>'(X, literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground(X)\n ),\n ( '<http://www.w3.org/2000/10/swap/log#uri>'(X, literal(U, type('<http://www.w3.org/2001/XMLSchema#string>'))),\n ( \\+got_uuid(U)\n -> uuid(Y, [uri(U)]),\n assertz(got_uuid(U))\n ; true\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#absoluteValue>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, U),\n Y is abs(U)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#acos>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is acos(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#acosh>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is acosh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#asin>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is asin(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#asinh>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is asinh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#atan>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is atan(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#atan2>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n Z is atan(U/V)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#atanh>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is atanh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#ceiling>'(X, Y) :-\n when(\n ( ground(X)\n ),\n (\n getnumber(X, U),\n Y is ceiling(U)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#cos>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is cos(U),\n !\n ; getnumber(Y, W),\n X is acos(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#cosh>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is cosh(U),\n !\n ; getnumber(Y, W),\n X is acosh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#degrees>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is U*180/pi,\n !\n ; getnumber(Y, W),\n X is W*pi/180\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#difference>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n Z is U-V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#equalTo>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U =:= V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#exponentiation>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ; ground([X, Z])\n ),\n ( getnumber(X, U),\n ( getnumber(Y, V),\n Z is U**V,\n !\n ; getnumber(Z, W),\n W =\\= 0,\n U =\\= 0,\n Y is log(W)/log(U)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#floor>'(X, Y) :-\n when(\n ( ground(X)\n ),\n (\n getnumber(X, U),\n Y is floor(U)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#greaterThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U > V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#integerQuotient>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n ( V =\\= 0\n -> Z is round(floor(U/V))\n ; throw(zero_division('<http://www.w3.org/2000/10/swap/math#integerQuotient>'([X, Y], Z)))\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#lessThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U < V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#logarithm>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ; ground([X, Z])\n ),\n ( getnumber(X, U),\n ( getnumber(Y, V),\n V =\\= 0,\n U =\\= 0,\n Z is log(U)/log(V),\n !\n ; getnumber(Z, W),\n Y is U**(1/W)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#max>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( max_list(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#memberCount>'(X, Y) :-\n when(\n ( nonvar(X)\n ),\n ( ( getlist(X, Z)\n -> true\n ; conj_list(X, U),\n ( ground(U)\n -> distinct(U, Z)\n ; Z = U\n )\n ),\n length(Z, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#min>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( min_list(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#negation>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is -U,\n !\n ; getnumber(Y, W),\n X is -W\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#notEqualTo>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U =\\= V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#notGreaterThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U =< V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#notLessThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U >= V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#product>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( product(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#quotient>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n ( V =\\= 0\n -> Z is U/V\n ; throw(zero_division('<http://www.w3.org/2000/10/swap/math#quotient>'([X, Y], Z)))\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#radians>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is U*pi/180,\n !\n ; getnumber(Y, W),\n X is W*180/pi\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#remainder>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n ( V =\\= 0\n -> Z is U-V*round(floor(U/V))\n ; throw(zero_division('<http://www.w3.org/2000/10/swap/math#remainder>'([X, Y], Z)))\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#rounded>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, U),\n Y is round(round(U))\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#roundedTo>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n F is 10**floor(V),\n Z is round(round(U*F))/F\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#sin>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is sin(U),\n !\n ; getnumber(Y, W),\n X is asin(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#sinh>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is sinh(U),\n !\n ; getnumber(Y, W),\n X is asinh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#sum>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( sum(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#tan>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is tan(U),\n !\n ; getnumber(Y, W),\n X is atan(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#tanh>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is tanh(U),\n !\n ; getnumber(Y, W),\n X is atanh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#capitalize>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground(X)\n ),\n ( sub_atom(X, 0, 1, _, A),\n upcase_atom(A, B),\n sub_atom(X, 1, _, 0, C),\n downcase_atom(C, D),\n atom_concat(B, D, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#concatenation>'(X, Y) :-\n when(\n ( nonvar(X)\n ),\n ( getlist(X, C),\n labelvars(C, 0, _, avar),\n ( member(D, C),\n var(D),\n var(Y)\n -> true\n ; findall(S,\n ( member(A, X),\n getcodes(A, S)\n ),\n Z\n ),\n flatten(Z, E),\n atom_codes(F, E),\n Y = literal(F, type('<http://www.w3.org/2001/XMLSchema#string>'))\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#contains>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground([X, Y])\n ),\n ( sub_atom(X, _, _, _, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#containsIgnoringCase>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground([X, Y])\n ),\n ( downcase_atom(X, U),\n downcase_atom(Y, V),\n sub_atom(U, _, _, _, V)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#containsRoughly>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground([X, Y])\n ),\n ( downcase_atom(X, R),\n downcase_atom(Y, S),\n normalize_space(atom(U), R),\n normalize_space(atom(V), S),\n sub_atom(U, _, _, _, V)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#endsWith>'(literal(X, _), literal(Y, _)) :-\n when(\n ( ground([X, Y])\n ),\n ( sub_atom(X, _, _, 0, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#equalIgnoringCase>'(literal(X, _), literal(Y, _)) :-\n when(\n ( ground([X, Y])\n ),\n ( downcase_atom(X, U),\n downcase_atom(Y, U)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#format>'([literal(A, _)|B], literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, D),\n subst([[[0'%, 0's], [0'~, 0'w]]], D, E),\n preformat(B, F),\n format_to_chars(E, F, G),\n atom_codes(C, G)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#greaterThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getstring(X, U),\n getstring(Y, V),\n U @> V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#join>'([X,Y], Z) :-\n when(\n ( nonvar(X)\n ),\n ( getlist(X, C),\n getcodes(Y, D),\n labelvars(C, 0, _, avar),\n ( member(E, C),\n var(E),\n var(Z)\n -> true\n ; findall([D,S],\n ( member(A, X),\n getcodes(A, S)\n ),\n U\n ),\n flatten(U, V),\n ( V = []\n -> F = V\n ; append(D, F, V)\n ),\n atom_codes(G, F),\n Z = literal(G, type('<http://www.w3.org/2001/XMLSchema#string>'))\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#lessThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getstring(X, U),\n getstring(Y, V),\n U @< V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#length>'(literal(A, _), B) :-\n when(\n ( ground(A)\n ),\n ( sub_atom(A, 0, B, 0, _)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#lowerCase>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground(X)\n ),\n ( downcase_atom(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#matches>'(literal(X, _), literal(Y, _)) :-\n when(\n ( ground([X, Y])\n ),\n ( regex(Y, X, _)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#notContainsRoughly>'(X, Y) :-\n \\+'<http://www.w3.org/2000/10/swap/string#containsRoughly>'(X, Y).\n\n'<http://www.w3.org/2000/10/swap/string#notEqualIgnoringCase>'(X, Y) :-\n \\+'<http://www.w3.org/2000/10/swap/string#equalIgnoringCase>'(X, Y).\n\n'<http://www.w3.org/2000/10/swap/string#notGreaterThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getstring(X, U),\n getstring(Y, V),\n U @=< V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#notLessThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getstring(X, U),\n getstring(Y, V),\n U @>= V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#notMatches>'(X, Y) :-\n \\+'<http://www.w3.org/2000/10/swap/string#matches>'(X, Y).\n\n'<http://www.w3.org/2000/10/swap/string#replace>'([literal(X, _),literal(Search, _),literal(Replace, _)], literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground([X,Search,Replace])\n ),\n ( ( regex(Search, X, [S|_])\n -> atom_codes(X, XC),\n string_codes(S, SC),\n atom_codes(Replace, RC),\n subst([[[0'$,0'1],SC]], RC, TC),\n subst([[SC,TC]], XC, YC),\n atom_codes(Y, YC)\n ; Y = X\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#replaceAll>'([literal(X, _),SearchList,ReplaceList], literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground([X,SearchList,ReplaceList])\n ),\n ( preformat(SearchList, SearchList2),\n preformat(ReplaceList, ReplaceList2),\n replace(SearchList2, ReplaceList2, X, Z),\n atom_string(Y, Z)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#scrape>'([literal(X, _),literal(Y, _)], literal(Z, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground([X,Y])\n ),\n ( regex(Y, X, [W|_]),\n atom_string(Z, W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#scrapeAll>'([literal(X, _),literal(Y, _)], Z) :-\n when(\n ( ground([X,Y])\n ),\n ( scrape(X, Y, V),\n preformat(Z, V)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#search>'([literal(X, _),literal(Y, _)], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( regex(Y, X, L),\n findall(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')),\n ( member(M, L),\n atom_string(A, M)\n ),\n Z\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#startsWith>'(literal(X, _), literal(Y, _)) :-\n when(\n ( ground([X, Y])\n ),\n ( sub_atom(X, 0, _, _, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#substring>'([literal(A, _), B, C], literal(D, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n !,\n when(\n ( ground([A, B, C])\n ),\n ( getint(B, I),\n getint(C, J),\n ( I < 1\n -> G is 0,\n H is J+I-1\n ; G is I-1,\n H is J\n ),\n ( H < 0\n -> D = ''\n ; sub_atom(A, G, H, _, D)\n )\n )\n ).\n'<http://www.w3.org/2000/10/swap/string#substring>'([literal(A, _), B], literal(D, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground([A, B])\n ),\n ( getint(B, I),\n sub_atom(A, 0, E, 0, _),\n J is E-I+1,\n ( I < 1\n -> G is 0,\n H is J+I-1\n ; G is I-1,\n H is J\n ),\n ( H < 0\n -> D = []\n ; sub_atom(A, G, H, _, D)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#upperCase>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground(X)\n ),\n ( upcase_atom(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/time#day>'(literal(X, _), literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground(X)\n ),\n ( sub_atom(X, 8, 2, _, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/time#localTime>'(literal(X, _), literal(Y, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))) :-\n when(\n ( ground(X)\n ),\n ( timestamp(Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/time#month>'(literal(X, _), literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground(X)\n ),\n ( sub_atom(X, 5, 2, _, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/time#year>'(literal(X, _), literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground(X)\n ),\n ( sub_atom(X, 0, 4, _, Y)\n )\n ).\n\n% RIF built-ins according to RIF Datatypes and Built-Ins 1.0 -- http://www.w3.org/TR/rif-dtb/\n\n% 4.1.1.1 pred:literal-not-identical\n\n'<http://www.w3.org/2007/rif-builtin-predicate#literal-not-identical>'([literal(A, B), literal(C, B)], D) :-\n \\+flag(restricted),\n when(\n ( ground([A, B, C])\n ),\n ( A \\== C\n -> D = true\n ; D = false\n )\n ).\n\n% 4.4.4 pred:iri-string\n\n'<http://www.w3.org/2007/rif-builtin-predicate#iri-string>'([A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ; nonvar(B)\n ),\n ( atom(A),\n sub_atom(A, 1, _, 1, U),\n atomic_list_concat(['<', U, '>'], A),\n !,\n ( U = B\n -> C = true\n ; C = false\n )\n ; nonvar(B),\n ( atomic_list_concat(['<', B, '>'], A)\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.1 Numeric Functions\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-add>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sum([A, B], C)\n )\n ).\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-subtract>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n C is U-V\n )\n ).\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-multiply>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n C is U*V\n )\n ).\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-divide>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( V =\\= 0\n -> C is U/V\n ; throw(zero_division('<http://www.w3.org/2007/rif-builtin-function#numeric-divide>'([A, B], C)))\n )\n )\n ).\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-integer-divide>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( V =\\= 0\n -> C is integer(floor(U/V))\n ; throw(zero_division('<http://www.w3.org/2007/rif-builtin-function#numeric-integer-divide>'([A, B], C)))\n )\n )\n ).\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-mod>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( V =\\= 0\n -> C is U-V*integer(floor(U/V))\n ; throw(zero_division('<http://www.w3.org/2007/rif-builtin-function#numeric-mod>'([A, B], C)))\n )\n )\n ).\n\n% 4.5.2.1 pred:numeric-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-equal>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U =:= V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.2.2 pred:numeric-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-less-than>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U < V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.2.3 pred:numeric-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-greater-than>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U > V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.2.4 pred:numeric-not-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-not-equal>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U =\\= V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.2.5 pred:numeric-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-less-than-or-equal>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U =< V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.2.6 pred:numeric-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-greater-than-or-equal>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U >= V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.6.1.1 func:not\n\n'<http://www.w3.org/2007/rif-builtin-function#not>'([A], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( getbool(A, U),\n ( ground(B)\n -> getbool(B, V)\n ; V = B\n ),\n inv(U, V)\n )\n ).\n\n% 4.6.2.1 pred:boolean-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#boolean-equal>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getbool(A, U),\n getbool(B, U)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.6.2.2 pred:boolean-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#boolean-less-than>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getbool(A, false),\n getbool(B, true)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.6.2.3 pred:boolean-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#boolean-greater-than>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getbool(A, true),\n getbool(B, false)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.7.1.1 func:compare @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-function#compare>'([literal(A, B), literal(C, B)], D) :-\n \\+flag(restricted),\n !,\n ( A @< C\n -> D = -1\n ; ( A == C\n -> D = 0\n ; ( A @> C\n -> D = 1\n )\n )\n ).\n\n% 4.7.1.2 func:concat\n\n'<http://www.w3.org/2007/rif-builtin-function#concat>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( findall(F,\n ( member(literal(S, type('<http://www.w3.org/2001/XMLSchema#string>')), A),\n atom_codes(S, F)\n ),\n C\n ),\n flatten(C, D),\n atom_codes(B, D)\n )\n ).\n\n% 4.7.1.3 func:string-join\n\n'<http://www.w3.org/2007/rif-builtin-function#string-join>'([A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(B, D),\n findall([D, E],\n ( member(literal(F, type('<http://www.w3.org/2001/XMLSchema#string>')), A),\n atom_codes(F, E)\n ),\n G\n ),\n ( G = [[_, H]|I]\n -> flatten([H|I], J),\n atom_codes(C, J)\n ; C = ''\n )\n )\n ).\n\n% 4.7.1.4 func:substring\n\n'<http://www.w3.org/2007/rif-builtin-function#substring>'([literal(A, _), B, C], literal(D, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n !,\n when(\n ( ground([A, B, C])\n ),\n ( getint(B, I),\n getint(C, J),\n ( I < 1\n -> G is 0,\n H is J+I-1\n ; G is I-1,\n H is J\n ),\n ( H < 0\n -> D = ''\n ; sub_atom(A, G, H, _, D)\n )\n )\n ).\n'<http://www.w3.org/2007/rif-builtin-function#substring>'([literal(A, _), B], literal(D, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getint(B, I),\n sub_atom(A, 0, E, 0, _),\n J is E-I+1,\n ( I < 1\n -> G is 0,\n H is J+I-1\n ; G is I-1,\n H is J\n ),\n ( H < 0\n -> D = []\n ; sub_atom(A, G, H, _, D)\n )\n )\n ).\n\n% 4.7.1.5 func:string-length\n\n'<http://www.w3.org/2007/rif-builtin-function#string-length>'([literal(A, _)], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( sub_atom(A, 0, B, 0, _)\n )\n ).\n\n% 4.7.1.6 func:upper-case\n\n'<http://www.w3.org/2007/rif-builtin-function#upper-case>'([literal(A, B)], literal(C, B)) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( upcase_atom(A, C)\n )\n ).\n\n% 4.7.1.7 func:lower-case\n\n'<http://www.w3.org/2007/rif-builtin-function#lower-case>'([literal(A, B)], literal(C, B)) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( downcase_atom(A, C)\n )\n ).\n\n% 4.7.1.8 func:encode-for-uri\n\n'<http://www.w3.org/2007/rif-builtin-function#encode-for-uri>'([literal(A, B)], literal(C, B)) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( www_form_encode(A, C)\n )\n ).\n\n% 4.7.1.11 func:substring-before @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-function#substring-before>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sub_atom(A, W, _, _, B),\n sub_atom(A, 0, W, _, C)\n )\n ).\n\n% 4.7.1.12 func:substring-after @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-function#substring-after>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sub_atom(A, _, _, W, B),\n sub_atom(A, _, W, 0, C)\n )\n ).\n\n% 4.7.2.1 pred:contains @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-predicate#contains>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sub_atom(B, 0, D, 0, _),\n sub_atom(A, _, D, _, B)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.7.2.2 pred:starts-with @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-predicate#starts-with>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sub_atom(A, 0, _, _, B)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.7.2.3 pred:ends-with @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-predicate#ends-with>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sub_atom(A, _, _, 0, B)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.7.2.4 pred:matches @@partial implementation: no flags\n\n'<http://www.w3.org/2007/rif-builtin-predicate#matches>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( regex(B, A, _)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.8.1.1 func:year-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#year-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(C, _, _, _, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.2 func:month-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#month-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, C, _, _, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.3 func:day-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#day-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, _, C, _, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.4 func:hours-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#hours-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, _, _, C, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.5 func:minutes-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#minutes-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, _, _, _, C, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.6 func:seconds-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#seconds-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, _, _, _, _, C, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.7 func:year-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#year-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n date(C, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.8 func:month-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#month-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n date(_, C, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.9 func:day-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#day-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n date(_, _, C, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.10 func:hours-from-time\n\n'<http://www.w3.org/2007/rif-builtin-function#hours-from-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n time(C, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.11 func:minutes-from-time\n\n'<http://www.w3.org/2007/rif-builtin-function#minutes-from-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n time(_, C, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.12 func:seconds-from-time\n\n'<http://www.w3.org/2007/rif-builtin-function#seconds-from-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n time(_, _, C, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.13 func:years-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#years-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], 0) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#years-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n yearmonthduration(C, U, []),\n D is C//12,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.14 func:months-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#months-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], 0) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#months-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n yearmonthduration(C, U, []),\n D is C-(C//12)*12,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.15 func:days-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#days-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], _) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#days-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n daytimeduration(C, U, []),\n D is integer(C)//86400,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.16 func:hours-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#hours-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], _) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#hours-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n daytimeduration(C, U, []),\n D is (integer(C)-(integer(C)//86400)*86400)//3600,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.17 func:minutes-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#minutes-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], _) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#minutes-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n daytimeduration(C, U, []),\n D is (integer(C)-(integer(C)//3600)*3600)//60,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.18 func:seconds-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#seconds-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], _) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#seconds-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n daytimeduration(C, U, []),\n D is C-(integer(C)//60)*60,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.19 func:timezone-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#timezone-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, _, _, _, _, _, C, U, []),\n ( ground(B)\n -> atom_codes(B, V),\n daytimeduration(D, V, []),\n D =:= C\n ; daytimeduration(C, E),\n atom_codes(B, E)\n )\n )\n ).\n\n% 4.8.1.20 func:timezone-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#timezone-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>'))], literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n date(_, _, _, C, U, []),\n ( ground(B)\n -> atom_codes(B, V),\n daytimeduration(D, V, []),\n D =:= C\n ; daytimeduration(C, E),\n atom_codes(B, E)\n )\n )\n ).\n\n% 4.8.1.21 func:timezone-from-time\n\n'<http://www.w3.org/2007/rif-builtin-function#timezone-from-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>'))], literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n time(_, _, _, C, U, []),\n ( ground(B)\n -> atom_codes(B, V),\n daytimeduration(D, V, []),\n D =:= C\n ; daytimeduration(C, E),\n atom_codes(B, E)\n )\n )\n ).\n\n% 4.8.1.22 func:subtract-dateTimes\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dateTimes>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n F is D-E,\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.23 func:subtract-dates\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dates>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n F is D-E,\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.24 func:subtract-times\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-times>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n F is D-E,\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.25 func:add-yearMonthDurations\n\n'<http://www.w3.org/2007/rif-builtin-function#add-yearMonthDurations>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n F is D+E,\n ( ground(C)\n -> atom_codes(C, W),\n yearmonthduration(G, W, []),\n G =:= F\n ; yearmonthduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.26 func:subtract-yearMonthDurations\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-yearMonthDurations>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n F is D-E,\n ( ground(C)\n -> atom_codes(C, W),\n yearmonthduration(G, W, []),\n G =:= F\n ; yearmonthduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.27 func:multiply-yearMonthDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#multiply-yearMonthDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), B], literal(C, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n yearmonthduration(D, U, []),\n getnumber(B, E),\n F is integer(round(D*E-1)+1),\n ( ground(C)\n -> atom_codes(C, W),\n yearmonthduration(G, W, []),\n G =:= F\n ; yearmonthduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.28 func:divide-yearMonthDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#divide-yearMonthDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), B], literal(C, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n yearmonthduration(D, U, []),\n getnumber(B, E),\n F is integer(round(D/E-1)+1),\n ( ground(C)\n -> atom_codes(C, W),\n yearmonthduration(G, W, []),\n G =:= F\n ; yearmonthduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.29 func:divide-yearMonthDuration-by-yearMonthDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#divide-yearMonthDuration-by-yearMonthDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n F is D/E,\n ( ground(C)\n -> C =:= F\n ; C = F\n )\n )\n ).\n\n% 4.8.1.30 func:add-dayTimeDurations\n\n'<http://www.w3.org/2007/rif-builtin-function#add-dayTimeDurations>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n F is D+E,\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.31 func:subtract-dayTimeDurations\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dayTimeDurations>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n F is D-E,\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.32 func:multiply-dayTimeDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#multiply-dayTimeDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), B], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n daytimeduration(D, U, []),\n getnumber(B, E),\n F is integer(round(D*E-1)+1),\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.33 func:divide-dayTimeDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#divide-dayTimeDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), B], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n daytimeduration(D, U, []),\n getnumber(B, E),\n F is integer(round(D/E-1)+1),\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.34 func:divide-dayTimeDuration-by-dayTimeDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#divide-dayTimeDuration-by-dayTimeDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n F is D/E,\n ( ground(C)\n -> C =:= F\n ; C = F\n )\n )\n ).\n\n% 4.8.1.35 func:add-yearMonthDuration-to-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#add-yearMonthDuration-to-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, E, F, G, H, I, J, U, []),\n yearmonthduration(K, V, []),\n L is E+K-1,\n Q is D+integer(floor(L/12)),\n R is L-integer(floor(L/12))*12+1,\n memotime(datime(Q, R, F, G, H, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is M+I+31536000-N-J,\n ( ground(C)\n -> atom_codes(C, W),\n datetime(P, W, []),\n O =:= P\n ; Offset is -J,\n stamp_date_time(O, date(Year, Month, Day, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n datetime(Year, Month, Day, Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.36 func:add-yearMonthDuration-to-date\n\n'<http://www.w3.org/2007/rif-builtin-function#add-yearMonthDuration-to-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#date>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, E, F, G, U, []),\n yearmonthduration(K, V, []),\n L is E+K-1,\n Q is D+integer(floor(L/12)),\n R is L-integer(floor(L/12))*12+1,\n memotime(datime(Q, R, F, 0, 0, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is (integer(floor(M+31536000-N-G))//60)*60,\n ( ground(C)\n -> atom_codes(C, W),\n date(P, W, []),\n O =:= P\n ; date(O, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.37 func:add-dayTimeDuration-to-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#add-dayTimeDuration-to-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, E, F, G, H, I, J, U, []),\n daytimeduration(K, V, []),\n L is I+K,\n memotime(datime(D, E, F, G, H, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is M+L+31536000-N-J,\n ( ground(C)\n -> atom_codes(C, W),\n datetime(P, W, []),\n O =:= P\n ; Offset is -J,\n stamp_date_time(O, date(Year, Month, Day, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n datetime(Year, Month, Day, Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.38 func:add-dayTimeDuration-to-date\n\n'<http://www.w3.org/2007/rif-builtin-function#add-dayTimeDuration-to-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#date>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, E, F, G, U, []),\n daytimeduration(K, V, []),\n L is integer(K),\n memotime(datime(D, E, F, 0, 0, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is (integer(floor(M+L+31536000-N))//86400)*86400-G,\n ( ground(C)\n -> atom_codes(C, W),\n date(P, W, []),\n O =:= P\n ; date(O, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.39 func:add-dayTimeDuration-to-time\n\n'<http://www.w3.org/2007/rif-builtin-function#add-dayTimeDuration-to-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#time>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, E, F, G, U, []),\n daytimeduration(K, V, []),\n L is F+K,\n memotime(datime(1972, 12, 31, D, E, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n Z is M+L+31536000-N-G,\n O is Z-86400*integer(floor(Z/86400)),\n ( ground(C)\n -> atom_codes(C, W),\n time(P, W, []),\n O =:= P-86400*integer(floor(P/86400))\n ; Offset is -G,\n stamp_date_time(O, date(_, _, _, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n time(Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.40 func:subtract-yearMonthDuration-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-yearMonthDuration-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, E, F, G, H, I, J, U, []),\n yearmonthduration(K, V, []),\n L is E-K-1,\n Q is D+integer(floor(L/12)),\n R is L-integer(floor(L/12))*12+1,\n memotime(datime(Q, R, F, G, H, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is M+I+31536000-N-J,\n ( ground(C)\n -> atom_codes(C, W),\n datetime(P, W, []),\n O =:= P\n ; Offset is -J,\n stamp_date_time(O, date(Year, Month, Day, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n datetime(Year, Month, Day, Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.41 func:subtract-yearMonthDuration-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-yearMonthDuration-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#date>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, E, F, G, U, []),\n yearmonthduration(K, V, []),\n L is E-K-1,\n Q is D+integer(floor(L/12)),\n R is L-integer(floor(L/12))*12+1,\n memotime(datime(Q, R, F, 0, 0, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is (integer(floor(M+31536000-N-G))//60)*60,\n ( ground(C)\n -> atom_codes(C, W),\n date(P, W, []),\n O =:= P\n ; date(O, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.42 func:subtract-dayTimeDuration-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dayTimeDuration-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, E, F, G, H, I, J, U, []),\n daytimeduration(K, V, []),\n L is I-integer(K),\n memotime(datime(D, E, F, G, H, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is M+L+31536000-N-J,\n ( ground(C)\n -> atom_codes(C, W),\n datetime(P, W, []),\n O =:= P\n ; Offset is -J,\n stamp_date_time(O, date(Year, Month, Day, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n datetime(Year, Month, Day, Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.43 func:subtract-dayTimeDuration-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dayTimeDuration-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#date>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, E, F, G, U, []),\n daytimeduration(K, V, []),\n L is -integer(K),\n memotime(datime(D, E, F, 0, 0, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is (integer(floor(M+L+31536000-N))//86400)*86400-G,\n ( ground(C)\n -> atom_codes(C, W),\n date(P, W, []),\n O =:= P\n ; date(O, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.44 func:subtract-dayTimeDuration-from-time\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dayTimeDuration-from-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#time>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, E, F, G, U, []),\n daytimeduration(K, V, []),\n L is F-K,\n memotime(datime(1972, 12, 31, D, E, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n Z is M+L+31536000-N-G,\n O is Z-86400*integer(floor(Z/86400)),\n ( ground(C)\n -> atom_codes(C, W),\n time(P, W, []),\n O =:= P-86400*integer(floor(P/86400))\n ; Offset is -G,\n stamp_date_time(O, date(_, _, _, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n time(Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.2.1 pred:dateTime-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D =:= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.2 pred:dateTime-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-less-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D < E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.3 pred:dateTime-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-greater-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D > E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.4 pred:date-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D =:= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.5 pred:date-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-less-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D < E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.6 pred:date-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-greater-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D > E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.7 pred:time-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D =:= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.8 pred:time-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-less-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D < E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.9 pred:time-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-greater-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D > E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.10 pred:duration-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#duration-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#duration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#duration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n duration(D, U, []),\n duration(E, V, []),\n ( D =:= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.11 pred:dayTimeDuration-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dayTimeDuration-less-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n ( D < E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.12 pred:dayTimeDuration-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dayTimeDuration-greater-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n ( D > E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.13 pred:yearMonthDuration-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#yearMonthDuration-less-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n ( D < E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.14 pred:yearMonthDuration-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#yearMonthDuration-greater-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n ( D > E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.15 pred:dateTime-not-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-not-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D =\\= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.16 pred:dateTime-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-less-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D =< E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.17 pred:dateTime-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-greater-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D >= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.18 pred:date-not-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-not-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D =\\= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.19 pred:date-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-less-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D =< E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.20 pred:date-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-greater-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D >= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.21 pred:time-not-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-not-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D =\\= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.22 pred:time-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-less-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D =< E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.23 pred:time-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-greater-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D >= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.24 pred:duration-not-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#duration-not-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#duration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#duration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n duration(D, U, []),\n duration(E, V, []),\n ( D =\\= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.25 pred:dayTimeDuration-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dayTimeDuration-less-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n ( D =< E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.26 pred:dayTimeDuration-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dayTimeDuration-greater-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n ( D >= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.27 pred:yearMonthDuration-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#yearMonthDuration-less-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n ( D =< E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.28 pred:yearMonthDuration-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#yearMonthDuration-greater-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n ( D >= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.10.1.1 func:PlainLiteral-from-string-lang\n\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-from-string-lang>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-from-string-lang>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(A, lang(C))) :-\n \\+flag(restricted),\n downcase_atom(B, C).\n\n% 4.10.1.2 func:string-from-PlainLiteral\n\n'<http://www.w3.org/2007/rif-builtin-function#string-from-PlainLiteral>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#string-from-PlainLiteral>'([literal(A, lang(_))], literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted).\n\n% 4.10.1.3 func:lang-from-PlainLiteral\n\n'<http://www.w3.org/2007/rif-builtin-function#lang-from-PlainLiteral>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal('', type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#lang-from-PlainLiteral>'([literal(_, lang(A))], literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted).\n\n% 4.10.1.4 func:PlainLiteral-compare @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-compare>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))], D) :-\n \\+flag(restricted),\n !,\n ( A @< C\n -> D = -1\n ; ( A == C\n -> D = 0\n ; ( A @> C\n -> D = 1\n )\n )\n ).\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-compare>'([literal(A, lang(B)), literal(C, lang(B))], D) :-\n \\+flag(restricted),\n ( A @< C\n -> D = -1\n ; ( A == C\n -> D = 0\n ; ( A @> C\n -> D = 1\n )\n )\n ).\n\n% 4.10.1.5 func:PlainLiteral-length\n\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-length>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n !,\n sub_atom(A, 0, C, 0, _).\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-length>'([literal(A, lang(_))], C) :-\n \\+flag(restricted),\n sub_atom(A, 0, C, 0, _).\n\n% 4.10.2.1 pred:matches-language-range @@partial implementation: no false results\n\n'<http://www.w3.org/2007/rif-builtin-predicate#matches-language-range>'([literal(A, lang(B)), literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))], true) :-\n \\+flag(restricted),\n A \\= '',\n atom_codes(C, U),\n regexp_wildcard(U, V),\n atom_codes(E, V),\n atomic_list_concat(['^', E], F),\n downcase_atom(F, G),\n downcase_atom(B, H),\n regex(G, H, _).\n\n% 4.11.3.1 pred:is-list\n\n'<http://www.w3.org/2007/rif-builtin-predicate#is-list>'([A], B) :-\n \\+flag(restricted),\n ( is_list(A)\n -> B = true\n ; B = false\n ).\n\n% 4.11.3.2 pred:list-contains\n\n'<http://www.w3.org/2007/rif-builtin-predicate#list-contains>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( member(B, A)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.11.4.1 func:make-list\n\n'<http://www.w3.org/2007/rif-builtin-function#make-list>'(A, A) :-\n \\+flag(restricted).\n\n% 4.11.4.2 func:count\n\n'<http://www.w3.org/2007/rif-builtin-function#count>'([A], B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( length(A, B)\n )\n ).\n\n% 4.11.4.3 func:get\n\n'<http://www.w3.org/2007/rif-builtin-function#get>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n ground(B)\n ),\n ( getnumber(B, U),\n nth0(U, A, C)\n )\n ).\n\n% 4.11.4.4 func:sublist\n\n'<http://www.w3.org/2007/rif-builtin-function#sublist>'([A, B, C], D) :-\n \\+flag(restricted),\n !,\n when(\n ( nonvar(A),\n ground([B, C])\n ),\n ( getint(B, U),\n getint(C, V),\n length(A, W),\n ( U < 0\n -> I is W+U\n ; I is U\n ),\n ( V < 0\n -> J is W+V\n ; J is V\n ),\n append(E, F, A),\n length(E, I),\n append(D, G, F),\n K is J-I,\n ( length(D, K)\n -> true\n ; G = []\n ),\n !\n )\n ).\n'<http://www.w3.org/2007/rif-builtin-function#sublist>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n ground(B)\n ),\n ( getint(B, U),\n length(A, W),\n ( U < 0\n -> I is W+U\n ; I is U\n ),\n append(E, C, A),\n length(E, I),\n !\n )\n ).\n\n% 4.11.4.5 func:append\n\n'<http://www.w3.org/2007/rif-builtin-function#append>'([A|B], C) :-\n \\+flag(restricted),\n append(A, B, C).\n\n% 4.11.4.6 func:concatenate\n\n'<http://www.w3.org/2007/rif-builtin-function#concatenate>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( append(A, B)\n )\n ).\n\n% 4.11.4.7 func:insert-before\n\n'<http://www.w3.org/2007/rif-builtin-function#insert-before>'([A, B, C], D) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n ground([B, C])\n ),\n ( getint(B, U),\n length(A, W),\n ( U < 0\n -> I is W+U\n ; I is U\n ),\n append(G, H, A),\n length(G, I),\n append([G, [C], H], D)\n )\n ).\n\n% 4.11.4.8 func:remove\n\n'<http://www.w3.org/2007/rif-builtin-function#remove>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n ground(B)\n ),\n ( getint(B, U),\n length(A, W),\n ( U < 0\n -> I is W+U\n ; I is U\n ),\n append(G, [_|T], A),\n length(G, I),\n append(G, T, C)\n )\n ).\n\n% 4.11.4.9 func:reverse\n\n'<http://www.w3.org/2007/rif-builtin-function#reverse>'([A], B) :-\n \\+flag(restricted),\n reverse(A, B).\n\n% 4.11.4.10 func:index-of\n\n'<http://www.w3.org/2007/rif-builtin-function#index-of>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n ground(B)\n ),\n ( findall(I,\n ( nth0(I, A, B)\n ),\n C\n )\n )\n ).\n\n% 4.11.4.11 func:union\n\n'<http://www.w3.org/2007/rif-builtin-function#union>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( append(A, C),\n distinct(C, B)\n )\n ).\n\n% 4.11.4.12 func:distinct-values\n\n'<http://www.w3.org/2007/rif-builtin-function#distinct-values>'([A], B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( distinct(A, B)\n )\n ).\n\n% 4.11.4.13 func:intersect\n\n'<http://www.w3.org/2007/rif-builtin-function#intersect>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground(A),\n ground(B)\n ),\n ( findall(I,\n ( member(I, A),\n member(I, B)\n ),\n C\n )\n )\n ).\n\n% 4.11.4.14 func:except\n\n'<http://www.w3.org/2007/rif-builtin-function#except>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground(A),\n ground(B)\n ),\n ( findall(I,\n ( member(I, A),\n \\+member(I, B)\n ),\n C\n )\n )\n ).\n\n% Prolog built-ins\n\nprolog_sym(abolish, abolish, rel).\nprolog_sym(abort, abort, rel).\nprolog_sym(abs, abs, func).\nprolog_sym(absolute_file_name, absolute_file_name, rel).\nprolog_sym(acos, acos, func).\nprolog_sym(acosh, acosh, func).\nprolog_sym(acyclic_term, acyclic_term, rel).\nprolog_sym(alarm, alarm, rel).\nprolog_sym(append, append, rel).\nprolog_sym(arg, arg, rel).\nprolog_sym(arithmetic_equal, =:=, rel).\nprolog_sym(arithmetic_greater_than, >, rel).\nprolog_sym(arithmetic_greater_than_or_equal, >=, rel).\nprolog_sym(arithmetic_less_than, <, rel).\nprolog_sym(arithmetic_less_than_or_equal, =<, rel).\nprolog_sym(arithmetic_not_equal, =\\=, rel).\nprolog_sym(asin, asin, func).\nprolog_sym(asinh, asinh, func).\nprolog_sym(assert, assert, rel).\nprolog_sym(asserta, asserta, rel).\nprolog_sym(assertz, assertz, rel).\nprolog_sym(at_end_of_stream, at_end_of_stream, rel).\nprolog_sym(atan, atan, func).\nprolog_sym(atan2, atan2, func).\nprolog_sym(atanh, atanh, func).\nprolog_sym(atom, atom, rel).\nprolog_sym(atom_chars, atom_chars, rel).\nprolog_sym(atom_codes, atom_codes, rel).\nprolog_sym(atom_concat, atom_concat, rel).\nprolog_sym(atom_length, atom_length, rel).\nprolog_sym(atom_number, atom_number, rel).\nprolog_sym(atomic, atomic, rel).\nprolog_sym(atomic_concat, atomic_concat, rel).\nprolog_sym(atomic_list_concat, atomic_list_concat, rel).\nprolog_sym(b_getval, b_getval, rel).\nprolog_sym(b_setval, b_setval, rel).\nprolog_sym(bagof, bagof, rel).\nprolog_sym(between, between, rel).\nprolog_sym(break, break, rel).\nprolog_sym(call, call, rel).\nprolog_sym(call_residue_vars, call_residue_vars, rel).\nprolog_sym(callable, callable, rel).\nprolog_sym(catch, catch, rel).\nprolog_sym(ceiling, ceiling, func).\nprolog_sym(char_code, char_code, rel).\nprolog_sym(char_conversion, char_conversion, rel).\nprolog_sym(char_type, char_type, rel).\nprolog_sym(character_count, character_count, rel).\nprolog_sym(clause, clause, rel).\nprolog_sym(close, close, rel).\nprolog_sym(code_type, code_type, rel).\nprolog_sym(compare, compare, rel).\nprolog_sym(compound, compound, rel).\nprolog_sym(conjunction, ',', rel).\nprolog_sym(consult, consult, rel).\nprolog_sym(copy_term, copy_term, rel).\nprolog_sym(copy_term_nat, copy_term_nat, rel).\nprolog_sym(cos, cos, func).\nprolog_sym(cosh, cosh, func).\nprolog_sym(cputime, cputime, func).\nprolog_sym(create_mutable, create_mutable, rel).\nprolog_sym(create_prolog_flag, create_prolog_flag, rel).\nprolog_sym(current_atom, current_atom, rel).\nprolog_sym(current_char_conversion, current_char_conversion, rel).\nprolog_sym(current_input, current_input, rel).\nprolog_sym(current_key, current_key, rel).\nprolog_sym(current_module, current_module, rel).\nprolog_sym(current_op, current_op, rel).\nprolog_sym(current_output, current_output, rel).\nprolog_sym(current_predicate, current_predicate, rel).\nprolog_sym(current_prolog_flag, current_prolog_flag, rel).\nprolog_sym(cut, !, rel).\nprolog_sym(cyclic_term, cyclic_term, rel).\nprolog_sym(date_time_stamp, date_time_stamp, rel).\nprolog_sym(date_time_value, date_time_value, rel).\nprolog_sym(day_of_the_week, day_of_the_week, rel).\nprolog_sym(delete, delete, rel).\nprolog_sym(dif, dif, rel).\nprolog_sym(discontiguous, discontiguous, rel).\nprolog_sym(disjunction, ;, rel).\nprolog_sym(display, display, rel).\nprolog_sym(div, div, func).\nprolog_sym(duplicate_term, duplicate_term, rel).\nprolog_sym(dynamic, dynamic, rel).\nprolog_sym(e, e, func).\nprolog_sym(ensure_loaded, ensure_loaded, rel).\nprolog_sym(environ, environ, rel).\nprolog_sym(epsilon, epsilon, func).\nprolog_sym(erase, erase, rel).\nprolog_sym(erf, erf, func).\nprolog_sym(erfc, erfc, func).\nprolog_sym(exception, exception, rel).\nprolog_sym(exists, exists, rel).\nprolog_sym(exp, exp, func).\nprolog_sym(fail, fail, rel).\nprolog_sym(false, false, rel).\nprolog_sym(file_base_name, file_base_name, rel).\nprolog_sym(file_name_extension, file_name_extension, rel).\nprolog_sym(findall, findall, rel).\nprolog_sym(flatten, flatten, rel).\nprolog_sym(float, float, rel).\nprolog_sym(float_fractional_part, float_fractional_part, func).\nprolog_sym(float_function, float, func).\nprolog_sym(float_integer_part, float_integer_part, func).\nprolog_sym(floor, floor, func).\nprolog_sym(flush_output, flush_output, rel).\nprolog_sym(forall, forall, rel).\nprolog_sym(format, format, rel).\nprolog_sym(format_time, format_time, rel).\nprolog_sym(freeze, freeze, rel).\nprolog_sym(frozen, frozen, rel).\nprolog_sym(functor, functor, rel).\nprolog_sym(garbage_collect, garbage_collect, rel).\nprolog_sym(garbage_collect_atoms, garbage_collect_atoms, rel).\nprolog_sym(gc, gc, rel).\nprolog_sym(gcd, gcd, func).\nprolog_sym(get, get, rel).\nprolog_sym(get_byte, get_byte, rel).\nprolog_sym(get_char, get_char, rel).\nprolog_sym(get_code, get_code, rel).\nprolog_sym(get_mutable, get_mutable, rel).\nprolog_sym(get_time, get_time, rel).\nprolog_sym(get0, get0, rel).\nprolog_sym(getcwd, getcwd, rel).\nprolog_sym(ground, ground, rel).\nprolog_sym(halt, halt, rel).\nprolog_sym(if, soft_cut, rel).\nprolog_sym(if_then, ->, rel).\nprolog_sym(if_then_else, if_then_else, rel).\nprolog_sym(ignore, ignore, rel).\nprolog_sym(include, include, rel).\nprolog_sym(initialization, initialization, rel).\nprolog_sym(instance, instance, rel).\nprolog_sym(integer, integer, rel).\nprolog_sym(integer_conjunction, /\\, func).\nprolog_sym(integer_disjunction, \\/, func).\nprolog_sym(integer_exclusive_disjunction, xor, func).\nprolog_sym(integer_function, integer, func).\nprolog_sym(integer_left_logical_shift, <<, func).\nprolog_sym(integer_negation, \\, func).\nprolog_sym(integer_power, ^, func).\nprolog_sym(integer_quotient, //, func).\nprolog_sym(integer_right_logical_shift, >>, func).\nprolog_sym(is, is, rel).\nprolog_sym(is_list, is_list, rel).\nprolog_sym(is_stream, is_stream, rel).\nprolog_sym(keysort, keysort, rel).\nprolog_sym(last, last, rel).\nprolog_sym(length, length, rel).\nprolog_sym(lgamma, lgamma, func).\nprolog_sym(line_count, line_count, rel).\nprolog_sym(line_position, line_position, rel).\nprolog_sym(listing, listing, rel).\nprolog_sym(log, log, func).\nprolog_sym(log10, log10, func).\nprolog_sym(lsb, lsb, func).\nprolog_sym(max, max, func).\nprolog_sym(max_list, max_list, rel).\nprolog_sym(member, member, rel).\nprolog_sym(memberchk, memberchk, rel).\nprolog_sym(message_to_string, message_to_string, rel).\nprolog_sym(min, min, func).\nprolog_sym(min_list, min_list, rel).\nprolog_sym(minus, -, func).\nprolog_sym(mod, mod, func).\nprolog_sym(msb, msb, func).\nprolog_sym(multifile, multifile, rel).\nprolog_sym(name, name, rel).\nprolog_sym(nb_current, nb_current, rel).\nprolog_sym(nb_delete, nb_delete, rel).\nprolog_sym(nb_getval, nb_getval, rel).\nprolog_sym(nb_linkarg, nb_linkarg, rel).\nprolog_sym(nb_linkval, nb_linkval, rel).\nprolog_sym(nb_setarg, nb_setarg, rel).\nprolog_sym(nb_setval, nb_setval, rel).\nprolog_sym(nl, nl, rel).\nprolog_sym(nonvar, nonvar, rel).\nprolog_sym(not_provable, \\+, rel).\nprolog_sym(not_unifiable, \\=, rel).\nprolog_sym(nth, nth, rel).\nprolog_sym(nth_clause, nth_clause, rel).\nprolog_sym(nth0, nth0, rel).\nprolog_sym(nth1, nth1, rel).\nprolog_sym(number, number, rel).\nprolog_sym(number_chars, number_chars, rel).\nprolog_sym(number_codes, number_codes, rel).\nprolog_sym(numbervars, numbervars, rel).\nprolog_sym(numlist, numlist, rel).\nprolog_sym(on_signal, on_signal, rel).\nprolog_sym(once, once, rel).\nprolog_sym(op, op, rel).\nprolog_sym(open, open, rel).\nprolog_sym(parse_time, parse_time, rel).\nprolog_sym(peek_byte, peek_byte, rel).\nprolog_sym(peek_char, peek_char, rel).\nprolog_sym(peek_code, peek_code, rel).\nprolog_sym(permutation, permutation, rel).\nprolog_sym(pi, pi, func).\nprolog_sym(plus, +, rel).\nprolog_sym(plus_function, +, func).\nprolog_sym(popcount, popcount, func).\nprolog_sym(portray_clause, portray_clause, rel).\nprolog_sym(power, **, func).\nprolog_sym(predicate_property, predicate_property, rel).\nprolog_sym(predsort, predsort, rel).\nprolog_sym(print, print, rel).\nprolog_sym(print_message, print_message, rel).\nprolog_sym(print_message_lines, print_message_lines, rel).\nprolog_sym(product, *, func).\nprolog_sym(prolog_flag, prolog_flag, rel).\nprolog_sym(prolog_load_context, prolog_load_context, rel).\nprolog_sym(prompt, prompt, rel).\nprolog_sym(put, put, rel).\nprolog_sym(put_byte, put_byte, rel).\nprolog_sym(put_char, put_char, rel).\nprolog_sym(put_code, put_code, rel).\nprolog_sym(quotient, /, func).\nprolog_sym(random, random, func).\nprolog_sym(random_float, random_float, func).\nprolog_sym(rational, rational, rel).\nprolog_sym(rational_function, rational, func).\nprolog_sym(rationalize, rationalize, func).\nprolog_sym(read, read, rel).\nprolog_sym(read_term, read_term, rel).\nprolog_sym(recorda, recorda, rel).\nprolog_sym(recorded, recorded, rel).\nprolog_sym(recordz, recordz, rel).\nprolog_sym(rem, rem, func).\nprolog_sym(rename_file, rename_file, rel).\nprolog_sym(repeat, repeat, rel).\nprolog_sym(retract, retract, rel).\nprolog_sym(retractall, retractall, rel).\nprolog_sym(reverse, reverse, rel).\nprolog_sym(round, round, func).\nprolog_sym(same_length, same_length, rel).\nprolog_sym(see, see, rel).\nprolog_sym(seeing, seeing, rel).\nprolog_sym(seen, seen, rel).\nprolog_sym(select, select, rel).\nprolog_sym(selectchk, selectchk, rel).\nprolog_sym(set_input, set_input, rel).\nprolog_sym(set_output, set_output, rel).\nprolog_sym(set_prolog_flag, set_prolog_flag, rel).\nprolog_sym(set_stream_position, set_stream_position, rel).\nprolog_sym(setarg, setarg, rel).\nprolog_sym(setof, setof, rel).\nprolog_sym(set_random, set_random, rel).\nprolog_sym(shell, shell, rel).\nprolog_sym(sign, sign, func).\nprolog_sym(simple, simple, rel).\nprolog_sym(sin, sin, func).\nprolog_sym(sinh, sinh, func).\nprolog_sym(skip, skip, rel).\nprolog_sym(sort, sort, rel).\nprolog_sym(source_file, source_file, rel).\nprolog_sym(source_location, source_location, rel).\nprolog_sym(sqrt, sqrt, func).\nprolog_sym(stamp_date_time, stamp_date_time, rel).\nprolog_sym(statistics, statistics, rel).\nprolog_sym(stream_position, stream_position, rel).\nprolog_sym(stream_position_data, stream_position_data, rel).\nprolog_sym(stream_property, stream_property, rel).\nprolog_sym(sub_atom, sub_atom, rel).\nprolog_sym(sublist, sublist, rel).\nprolog_sym(subsumes_term, subsumes_term, rel).\nprolog_sym(succ, succ, rel).\nprolog_sym(sum_list, sum_list, rel).\nprolog_sym(tab, tab, rel).\nprolog_sym(tan, tan, func).\nprolog_sym(tanh, tanh, func).\nprolog_sym(tell, tell, rel).\nprolog_sym(telling, telling, rel).\nprolog_sym(term_greater_than, @>, rel).\nprolog_sym(term_greater_than_or_equal, @>=, rel).\nprolog_sym(term_hash, term_index, rel).\nprolog_sym(term_identical, ==, rel).\nprolog_sym(term_less_than, @<, rel).\nprolog_sym(term_less_than_or_equal, @=<, rel).\nprolog_sym(term_not_identical, \\==, rel).\nprolog_sym(term_to_atom, term_to_atom, rel).\nprolog_sym(term_variables, term_variables, rel).\nprolog_sym(throw, throw, rel).\nprolog_sym(time, time, rel).\nprolog_sym(time_file, time_file, rel).\nprolog_sym(told, told, rel).\nprolog_sym(true, true, rel).\nprolog_sym(truncate, truncate, func).\nprolog_sym(unifiable, unifiable, rel).\nprolog_sym(unify, =, rel).\nprolog_sym(unify_with_occurs_check, unify_with_occurs_check, rel).\nprolog_sym(univ, =.., rel).\nprolog_sym(unknown, unknown, rel).\nprolog_sym(update_mutable, update_mutable, rel).\nprolog_sym(use_module, use_module, rel).\nprolog_sym(var, var, rel).\nprolog_sym(variant, variant, rel).\nprolog_sym(version, version, rel).\nprolog_sym(when, when, rel).\nprolog_sym(with_output_to, with_output_to, rel).\nprolog_sym(write, write, rel).\nprolog_sym(write_canonical, write_canonical, rel).\nprolog_sym(write_term, write_term, rel).\nprolog_sym(writeln, writeln, rel).\nprolog_sym(writeq, writeq, rel).\n\n%\n% Support\n%\n\ndef_pfx('math:', '<http://www.w3.org/2000/10/swap/math#>').\ndef_pfx('e:', '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#>').\ndef_pfx('list:', '<http://www.w3.org/2000/10/swap/list#>').\ndef_pfx('xsd:', '<http://www.w3.org/2001/XMLSchema#>').\ndef_pfx('log:', '<http://www.w3.org/2000/10/swap/log#>').\ndef_pfx('r:', '<http://www.w3.org/2000/10/swap/reason#>').\ndef_pfx('rdfs:', '<http://www.w3.org/2000/01/rdf-schema#>').\ndef_pfx('time:', '<http://www.w3.org/2000/10/swap/time#>').\ndef_pfx('rdf:', '<http://www.w3.org/1999/02/22-rdf-syntax-ns#>').\ndef_pfx('string:', '<http://www.w3.org/2000/10/swap/string#>').\ndef_pfx('owl:', '<http://www.w3.org/2002/07/owl#>').\ndef_pfx('n3:', '<http://www.w3.org/2004/06/rei#>').\n\nput_pfx(_, URI) :-\n atomic_list_concat(['<', URI, '>'], U),\n pfx(_, U),\n !.\nput_pfx(_, URI) :-\n atomic_list_concat(['<', URI, '>'], U),\n def_pfx(Pf, U),\n \\+pfx(Pf, _),\n !,\n assertz(pfx(Pf, U)).\nput_pfx(Pf, URI) :-\n atomic_list_concat(['<', URI, '>'], U),\n fresh_pf(Pf, Pff),\n assertz(pfx(Pff, U)).\n\nfresh_pf(Pf, Pfx) :-\n atom_concat(Pf, ':', Pfx),\n \\+pfx(Pfx, _),\n !.\nfresh_pf(_, Pfx) :-\n gensym(ns, Pfn),\n fresh_pf(Pfn, Pfx).\n\ncnt(A) :-\n nb_getval(A, B),\n C is B+1,\n nb_setval(A, C),\n ( flag('debug-cnt'),\n C mod 10000 =:= 0\n -> format(user_error, '~w = ~w~n', [A, C]),\n flush_output(user_error)\n ; true\n ).\n\ncnt(A, I) :-\n nb_getval(A, B),\n C is B+I,\n nb_setval(A, C),\n ( flag('debug-cnt'),\n C mod 10000 =:= 0\n -> format(user_error, '~w = ~w~n', [A, C]),\n flush_output(user_error)\n ; true\n ).\n\nwithin_scope([A, B]) :-\n ( var(B)\n -> B = 1\n ; true\n ),\n ( B = 0\n -> brake\n ; nb_getval(limit, C),\n ( C < B\n -> nb_setval(limit, B)\n ; true\n ),\n span(B)\n ),\n nb_getval(scope, A).\n\ndomain(A, true, B) :-\n !,\n findall('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'(C, _),\n ( member(C, A)\n ),\n D\n ),\n conj_list(B, D).\ndomain(_, B, B).\n\nexopred(P, S, O) :-\n ( var(P),\n var(S),\n var(O)\n -> pred(P),\n H =.. [P, S, O],\n clause(H, true)\n ; ( var(P)\n -> pred(P)\n ; atom(P),\n current_predicate(P/2)\n ),\n call(P, S, O)\n ).\n\nexogen :-\n forall(\n ( clause(exopred(P, S, O), Body),\n ( nonvar(S)\n ; nonvar(O)\n )\n ),\n ( ( var(P)\n -> pred(P)\n ; atom(P),\n current_predicate(P/2)\n ),\n Head =.. [P, S, O],\n ( \\+clause(Head, Body)\n -> assertz(Head :- Body)\n ; true\n )\n )\n ).\nexogen :-\n \\+flag('multi-query').\n\nucall(A) :-\n ( A = (B, C)\n -> vcall(B),\n ucall(C)\n ; vcall(A)\n ).\n\nvcall(A) :-\n ( ( A =.. [_, V, W]\n ; A = exopred(_, V, W)\n ),\n ( is_gl(V)\n ; is_gl(W)\n )\n -> unify(A, B)\n ; B = A\n ),\n ( B =.. [C, D, E],\n pred(C),\n ( is_gl(D)\n ; is_gl(E)\n )\n -> G =.. [C, H, I],\n call(G),\n unify(H, D),\n unify(I, E)\n ; call(B)\n ).\n\nis_gl(A) :-\n nonvar(A),\n \\+is_list(A),\n ( A = (_, _),\n !\n ; A =.. [F, _, _],\n F \\= literal,\n F \\= rdiv,\n !\n ; A = exopred(_, _, _)\n ).\n\nunify(A, true) :-\n \\+flag('no-erase'),\n nonvar(A),\n A = '<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(X, Y),\n nonvar(Y),\n labelvars(X, 0, _),\n catch(call(Y), _, fail).\nunify(A, B) :-\n \\+flag('no-erase'),\n nonvar(A),\n A = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(X, Y),\n conj_list(Y, C),\n length(C, D),\n D > 1,\n ndsplit(C, E, F),\n E \\= [],\n F \\= [],\n conj_list(G, F),\n ( catch(call(G), _, fail)\n -> conj_list(H, E),\n B = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(X, H)\n ; ( G = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, I)\n -> catch(call(I), _, fail)\n ; '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, G)\n ),\n B = true\n ).\nunify(A, B) :-\n nonvar(A),\n A = exopred(P, S, O),\n ( ( nonvar(B)\n ; nonvar(P)\n )\n -> ( nonvar(P)\n -> atom(P)\n ; true\n ),\n B =.. [P, T, R],\n atom(P),\n unify(S, T),\n unify(O, R)\n ; B = exopred(P, T, R),\n unify(S, T),\n unify(O, R)\n ),\n !.\nunify(A, B) :-\n nonvar(B),\n B = exopred(P, S, O),\n ( ( nonvar(A)\n ; nonvar(P)\n )\n -> ( nonvar(P)\n -> atom(P)\n ; true\n ),\n A =.. [P, T, R],\n atom(P),\n unify(S, T),\n unify(O, R)\n ; A = exopred(P, T, R),\n unify(S, T),\n unify(O, R)\n ),\n !.\nunify(A, B) :-\n is_list(A),\n !,\n getlist(B, C),\n C = A.\nunify(A, B) :-\n is_list(B),\n !,\n getlist(A, C),\n C = B.\nunify(A, B) :-\n nonvar(A),\n nonvar(B),\n ( A = (_, _)\n ; B = (_, _)\n ),\n !,\n conj_list(A, C),\n conj_list(B, D),\n includes(C, D),\n includes(D, C).\nunify(A, B) :-\n nonvar(A),\n nonvar(B),\n A =.. [P, S, O],\n B =.. [P, T, R],\n !,\n unify(S, T),\n unify(O, R).\nunify(A, A).\n\nconj_list(true, []) :-\n !.\nconj_list(A, [A]) :-\n A \\= (_, _),\n A \\= false,\n !.\nconj_list((A, B), [A|C]) :-\n conj_list(B, C).\n\nconj_append(A, true, A) :-\n !.\nconj_append((A, B), C, (A, D)) :-\n conj_append(B, C, D),\n !.\nconj_append(A, B, (A, B)).\n\ncflat([], []).\ncflat([A|B], C) :-\n cflat(B, D),\n copy_term_nat(A, E),\n ( E = (_, _),\n conj_list(E, F)\n -> append(F, D, C)\n ; ( E = true\n -> C = D\n ; C = [E|D]\n )\n ).\n\ncouple([], [], []).\ncouple([A|B], [C|D], [[A, C]|E]) :-\n couple(B, D, E).\n\nincludes(_, []) :-\n !.\nincludes(X, [Y|Z]) :-\n member(U, X),\n unify(U, Y),\n includes(X, Z).\n\nconjoin([X], X) :-\n !.\nconjoin([true|Y], Z) :-\n conjoin(Y, Z),\n !.\nconjoin([X|Y], Z) :-\n conjoin(Y, U),\n conj_append(X, U, V),\n ( ground(V)\n -> conj_list(V, A),\n sort(A, B),\n conj_list(Z, B)\n ; Z = V\n ).\n\ndifference([true, _], true) :-\n !.\ndifference([X, true], X) :-\n !.\ndifference([X, Y], Z) :-\n conj_list(X, U),\n conj_list(Y, V),\n difference(U, V, W),\n distinct(W, J),\n conj_list(Z, J).\n\ndifference([], _, []) :-\n !.\ndifference([X|Y], U, V) :-\n member(Z, U),\n unify(X, Z),\n !,\n difference(Y, U, V).\ndifference([X|Y], U, [X|V]) :-\n difference(Y, U, V).\n\nintersect([X], X) :-\n !.\nintersect([true|_], true) :-\n !.\nintersect([X|Y], Z) :-\n intersect(Y, I),\n conj_list(X, U),\n conj_list(I, V),\n intersect(U, V, W),\n distinct(W, J),\n conj_list(Z, J),\n !.\n\nintersect([], _, []) :-\n !.\nintersect([X|Y], U, V) :-\n member(Z, U),\n unify(X, Z),\n V = [X|W],\n intersect(Y, U, W).\nintersect([_|Y], U, V) :-\n intersect(Y, U, V).\n\ncartesian([], []).\ncartesian([A|B], [C|D]) :-\n member(C, A),\n cartesian(B, D).\n\ndistinct(A, B) :-\n ( ground(A)\n -> distinct_hash(A, B)\n ; distinct_value(A, B)\n ).\n\ndistinct_hash([], []) :-\n ( retract(hash_value(_, _)),\n fail\n ; true\n ),\n !.\ndistinct_hash([A|B], C) :-\n term_index(A, D),\n ( hash_value(D, E)\n -> ( unify(A, E)\n -> C = F\n ; C = [A|F]\n )\n ; assertz(hash_value(D, A)),\n C = [A|F]\n ),\n distinct_hash(B, F).\n\ndistinct_value([], []).\ndistinct_value([A|B], [A|D]) :-\n nonvar(A),\n !,\n del(B, A, E),\n distinct_value(E, D).\ndistinct_value([_|A], B) :-\n distinct_value(A, B).\n\ndel([], _, []).\ndel([A|B], C, D) :-\n copy_term_nat(A, Ac),\n copy_term_nat(C, Cc),\n unify(Ac, Cc),\n !,\n del(B, C, D).\ndel([A|B], C, [A|D]) :-\n del(B, C, D).\n\nsubst(_, [], []).\nsubst(A, B, C) :-\n member([D, E], A),\n append(D, F, B),\n !,\n append(E, G, C),\n subst(A, F, G).\nsubst(A, [B|C], [B|D]) :-\n subst(A, C, D).\n\nreplace([], [], X, X) :-\n !.\nreplace([Search|SearchRest], [Replace|ReplaceRest], X, Y) :-\n atomic_list_concat(['(', Search, ')'], Scap),\n scrape(X, Scap, Scrape),\n atom_codes(Replace, RC),\n srlist(Scrape, RC, Subst),\n atom_codes(X, XC),\n subst(Subst, XC, ZC),\n atom_codes(Z, ZC),\n replace(SearchRest, ReplaceRest, Z, Y).\n\nscrape(X, Y, [V|Z]) :-\n regex(Y, X, [W|_]),\n !,\n atom_string(V, W),\n sub_atom(X, _, _, I, V),\n sub_atom(X, _, I, 0, U),\n scrape(U, Y, Z).\nscrape(_, _, []).\n\nsrlist([], _, []).\nsrlist([A|B], C, [[E,C]|D]) :-\n string_codes(A, E),\n srlist(B, C, D).\n\nquicksort([], []).\nquicksort([A|B], C) :-\n split(A, B, D, E),\n quicksort(D, F),\n quicksort(E, G),\n append(F, [A|G], C).\n\nsplit(_, [], [], []).\nsplit(A, [B|C], [B|D], E) :-\n sort([A, B], [B, A]),\n !,\n split(A, C, D, E).\nsplit(A, [B|C], D, [B|E]) :-\n split(A, C, D, E).\n\ndsplit([], [], []).\ndsplit([A|B], [A|C], D):-\n dsplit(B, C, D).\ndsplit([A|B], C, [A|D]):-\n predicate_property(A, dynamic),\n dsplit(B, C, D).\n\nndsplit([], [], []).\nndsplit([A|B], [A|C], D):-\n ndsplit(B, C, D).\nndsplit([A|B], C, [A|D]):-\n ndsplit(B, C, D).\n\nlast_tail([], []) :-\n !.\nlast_tail([_|B], B) :-\n \\+is_list(B),\n !.\nlast_tail([_|B], C) :-\n last_tail(B, C).\n\nsub_list(A, A) :-\n !.\nsub_list([A|B], C) :-\n sub_list(B, A, C).\n\nsub_list(A, _, A) :-\n !.\nsub_list([A|B], C, [C|D]) :-\n !,\n sub_list(B, A, D).\nsub_list([A|B], _, C) :-\n sub_list(B, A, C).\n\ne_transpose([], []).\ne_transpose([A|B], C) :-\n e_transpose(A, [A|B], C).\n\ne_transpose([], _, []).\ne_transpose([_|A], B, [C|D]) :-\n lists_fr(B, C, E),\n e_transpose(A, E, D).\n\nlists_fr([], [], []).\nlists_fr([[A|B]|C], [A|D], [B|E]) :-\n lists_fr(C, D, E).\n\nsum([], 0) :-\n !.\nsum([A|B], C) :-\n getnumber(A, X),\n sum(B, D),\n C is X+D.\n\nproduct([], 1) :-\n !.\nproduct([A|B], C) :-\n getnumber(A, X),\n product(B, D),\n C is X*D.\n\navg(A, B) :-\n sum(A, As),\n length(A, An),\n B is As/An.\n\ncov([A, B], C) :-\n avg(A, Am),\n avg(B, Bm),\n cov1(A, B, Am, Bm, Cp),\n length(A, An),\n C is Cp/(An-1).\n\ncov1([], [], _, _, 0).\ncov1([A|B], [C|D], E, F, G) :-\n cov1(B, D, E, F, H),\n getnumber(A, I),\n getnumber(C, J),\n G is (I-E)*(J-F)+H.\n\npcc([A, B], C) :-\n avg(A, Am),\n avg(B, Bm),\n cov1(A, B, Am, Bm, Cp),\n std1(A, Am, Ap),\n std1(B, Bm, Bp),\n C is Cp/sqrt(Ap*Bp).\n\nrms(A, B) :-\n rms1(A, Ar),\n length(A, An),\n B is sqrt(Ar/An).\n\nrms1([], 0).\nrms1([A|B], C) :-\n rms1(B, D),\n getnumber(A, E),\n C is E^2+D.\n\nstd(A, B) :-\n avg(A, Am),\n std1(A, Am, As),\n length(A, An),\n B is sqrt(As/(An-1)).\n\nstd1([], _, 0).\nstd1([A|B], C, D) :-\n std1(B, C, E),\n getnumber(A, F),\n D is (F-C)^2+E.\n\nbmax([A|B], C) :-\n bmax(B, A, C).\n\nbmax([], A, A).\nbmax([A|B], C, D) :-\n getnumber(A, X),\n getnumber(C, Y),\n ( X > Y\n -> bmax(B, A, D)\n ; bmax(B, C, D)\n ).\n\nbmin([A|B], C) :-\n bmin(B, A, C).\n\nbmin([], A, A).\nbmin([A|B], C, D) :-\n getnumber(A, X),\n getnumber(C, Y),\n ( X < Y\n -> bmin(B, A, D)\n ; bmin(B, C, D)\n ).\n\ninconsistent(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>')|B]) :-\n memberchk('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>'), B),\n !.\ninconsistent(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>')|B]) :-\n memberchk('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>'), B),\n !.\ninconsistent([_|B]) :-\n inconsistent(B).\n\ninverse('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>'),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>')) :-\n !.\ninverse('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>'),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>')).\n\nbnet :-\n ( '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#conditional>'([A|B], _),\n sort(B, C),\n findall(Y,\n ( '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#conditional>'([A|X], Y),\n sort(X, C)\n ),\n L\n ),\n sum(L, S),\n length(L, N),\n Z is S/N,\n \\+bcnd([A|B], _),\n assertz(bcnd([A|B], Z)),\n inverse(A, D),\n \\+bcnd([D|B], _),\n E is 1-Z,\n assertz(bcnd([D|B], E)),\n fail\n ; bcnd(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, _)|B], _),\n ( \\+bvar(A),\n assertz(bvar(A))\n ; true\n ),\n member('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(C, _), B),\n \\+bref(C, A),\n assertz(bref(C, A)),\n \\+bvar(C),\n assertz(bvar(C)),\n fail\n ; true\n ).\n\nbval('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>').\nbval('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>').\n\nbrel('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, _), '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(B, _)) :-\n bref(A, B),\n !.\nbrel(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(B, _)) :-\n bref(C, B),\n brel(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(C, _)).\n\nbpar([], []) :-\n !.\nbpar(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, _)|B], [A|C]) :-\n bpar(B, C).\n\nbget(A, B, 1.0) :-\n memberchk(A, B),\n !.\nbget('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>'), B, 0.0) :-\n memberchk('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>'), B),\n !.\nbget('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>'), B, C) :-\n ( memberchk('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>'), B),\n !,\n C is 0.0\n ;\n !,\n bget('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>'), B, D),\n C is 1-D\n ).\nbget(A, B, C) :-\n ( bgot(A, B, C)\n -> true\n ; ( member(X, B),\n brel(A, X),\n member(G, B),\n findall(_,\n ( member(Z, [A|B]),\n brel(G, Z)\n ),\n []\n ),\n del(B, G, H),\n !,\n bget(G, [A|H], U),\n bget(A, H, V),\n bget(G, H, W),\n ( W < 1e-15\n -> C is 0.5\n ; E is U*V/W,\n bmin([E, 1.0], C)\n )\n ; findall([Z, Y],\n ( bcnd([A|O], P),\n bcon(O, B, Q),\n Z is P*Q,\n bpar(O, Y)\n ),\n L\n ),\n findall(Z,\n ( member([_, Z], L)\n ),\n N\n ),\n distinct(N, I),\n findall(Z,\n ( member(Y, I),\n findall(P,\n ( member([P, Y], L)\n ),\n Q\n ),\n sum(Q, R),\n length(Q, S),\n length(Y, T),\n ( Q = []\n -> Z is 0.0\n ; D is 2**(T-ceiling(log(S)/log(2))),\n ( D < 1\n -> Z is R*D\n ; Z is R\n )\n )\n ),\n J\n ),\n ( J = []\n -> C is 0.0\n ; bmax(J, C)\n )\n ),\n assertz(bgot(A, B, C))\n ).\n\nbcon([], _, 1.0) :-\n !.\nbcon(_, B, 0.5) :-\n inconsistent(B),\n !.\nbcon([A|B], C, D) :-\n bget(A, C, E),\n bcon(B, [A|C], F),\n D is E*F.\n\ntmp_file(A) :-\n ( current_prolog_flag(dialect, swi),\n current_prolog_flag(windows, true),\n current_prolog_flag(pid, B)\n -> atomic_list_concat(['pl_eye_', B, '_'], C)\n ; C = 'eye'\n ),\n tmp_file(C, A).\n\nexec(A, B) :-\n shell(A, B),\n ( B =:= 0\n -> true\n ; throw(exec_error(A))\n ).\n\ngetcwd(A) :-\n working_directory(A, A).\n\n%\n% Modified Base64 for XML identifiers\n%\n\nbase64xml(A, B) :-\n base64(A, C),\n atom_codes(C, D),\n subst([[[0'+], [0'_]], [[0'/], [0':]], [[0'=], []]], D, E),\n atom_codes(B, E).\n\nterm_index(A, B) :-\n term_hash(A, B).\n\nif_then_else(A, B, C) :-\n ( catch(call(A), _, fail)\n -> catch(call(B), _, fail)\n ; catch(call(C), _, fail)\n ).\n\nsoft_cut(A, B, C) :-\n ( catch(call(A), _, fail)\n *-> catch(call(B), _, fail)\n ; catch(call(C), _, fail)\n ).\n\ninv(false, true).\ninv(true, false).\n\n+(A, B, C) :-\n plus(A, B, C).\n\n':-'(A, B) :-\n ( var(A)\n -> cpred(C),\n A =.. [C, _, _]\n ; true\n ),\n ( A = exopred(P, S, O)\n -> Ax =.. [P, S, O]\n ; Ax = A\n ),\n clause(Ax, D),\n ( \\+flag(nope),\n ( D = when(H, I)\n -> conj_append(J, istep(Src, _, _, _), I),\n B = when(H, J)\n ; conj_append(B, istep(Src, _, _, _), D)\n )\n -> term_index(true, Pnd),\n ( \\+prfstep(':-'(Ax, B), true, Pnd, ':-'(Ax, B), _, forward, Src)\n -> assertz(prfstep(':-'(Ax, B), true, Pnd, ':-'(Ax, B), _, forward, Src))\n ; true\n )\n ; D = B\n ).\n\nsub_atom_last(A, B, C, D, E) :-\n sub_atom(A, B, C, D, E),\n F is B+1,\n sub_atom(A, F, _, 0, G),\n ( sub_atom(G, _, C, _, E)\n -> sub_atom_last(G, B, C, D, E)\n ; true\n ).\n\nlookup(A, B, C) :-\n tabl(A, B, C),\n !.\nlookup(A, B, C) :-\n var(A),\n nb_getval(tabl, M),\n N is M+1,\n nb_setval(tabl, N),\n atom_number(I, N),\n atomic_list_concat([B, '_tabl_entry_', I], A),\n assertz(tabl(A, B, C)).\n\nescape_string([], []) :-\n !.\nescape_string([0'\\t|A], [0'\\\\, 0't|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\\b|A], [0'\\\\, 0'b|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\\n|A], [0'\\\\, 0'n|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\\r|A], [0'\\\\, 0'r|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\\f|A], [0'\\\\, 0'f|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\"|A], [0'\\\\, 0'\"|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\\\\|A], [0'\\\\, 0'\\\\|B]) :-\n !,\n escape_string(A, B).\nescape_string([A|B], [A|C]) :-\n escape_string(B, C).\n\nescape_squote([], []) :-\n !.\nescape_squote([0''|A], [0'\\\\, 0''|B]) :-\n !,\n escape_squote(A, B).\nescape_squote([A|B], [A|C]) :-\n escape_squote(B, C).\n\nescape_unicode([], []) :-\n !.\nescape_unicode([A, B|C], D) :-\n 0xD800 =< A,\n A =< 0xDBFF,\n 0xDC00 =< B,\n B =< 0xDFFF,\n E is 0x10000+(A-0xD800)*0x400+(B-0xDC00),\n ( 0x100000 =< E\n -> with_output_to(codes(F), format('\\\\U00~16R', [E]))\n ; with_output_to(codes(F), format('\\\\U000~16R', [E]))\n ),\n append(F, G, D),\n !,\n escape_unicode(C, G).\nescape_unicode([A|B], [A|C]) :-\n escape_unicode(B, C).\n\nesplit_string([], _, [], []) :-\n !.\nesplit_string([], _, A, [A]) :-\n !.\nesplit_string([A|B], C, [], D) :-\n memberchk(A, C),\n !,\n esplit_string(B, C, [], D).\nesplit_string([A|B], C, D, [D|E]) :-\n memberchk(A, C),\n !,\n esplit_string(B, C, [], E).\nesplit_string([A|B], C, D, E) :-\n append(D, [A], F),\n esplit_string(B, C, F, E).\n\nquant(A, some) :-\n var(A),\n !.\nquant('<http://www.w3.org/2000/10/swap/log#implies>'(_, _), allv) :-\n !.\nquant(':-'(_, _), allv) :-\n !.\nquant(answer('<http://www.w3.org/2000/10/swap/log#implies>', _, _), allv) :-\n !.\nquant(answer(':-', _, _), allv) :-\n !.\nquant(answer('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tactic>', _, _), allv) :-\n !.\nquant(_, some).\n\nlabelvars(A, B, C) :-\n quant(A, Q),\n labelvars(A, B, C, Q).\n\nlabelvars(A, B, C, D) :-\n var(A),\n !,\n atom_number(E, B),\n atomic_list_concat([D, E], A), % failing when A is an attributed variable\n C is B+1.\nlabelvars(A, B, B, _) :-\n atomic(A),\n !.\nlabelvars('<http://www.w3.org/2000/10/swap/log#implies>'(A, B), C, C, D) :-\n D \\= avar,\n nonvar(A),\n nonvar(B),\n !.\nlabelvars((A, B), C, D, Q) :-\n !,\n labelvars(A, C, E, Q),\n labelvars(B, E, D, Q).\nlabelvars([A|B], C, D, Q) :-\n !,\n labelvars(A, C, E, Q),\n labelvars(B, E, D, Q).\nlabelvars(A, B, C, Q) :-\n nonvar(A),\n functor(A, _, D),\n labelvars(0, D, A, B, C, Q).\n\nlabelvars(A, A, _, B, B, _) :-\n !.\nlabelvars(A, B, C, D, E, Q) :-\n F is A+1,\n arg(F, C, G),\n labelvars(G, D, H, Q),\n labelvars(F, B, C, H, E, Q).\n\nrelabel(A, A) :-\n var(A),\n !,\n nb_getval(wn, W),\n labelvars(A, W, N, allv),\n nb_setval(wn, N).\nrelabel([], []) :-\n !.\nrelabel([A|B], [C|D]) :-\n !,\n relabel(A, C),\n relabel(B, D).\nrelabel(A, B) :-\n atom(A),\n !,\n ( '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>'(A, B)\n -> labelvars(B, 0, _)\n ; B = A\n ).\nrelabel(A, A) :-\n number(A),\n !.\nrelabel(A, B) :-\n A =.. [C|D],\n relabel(C, E),\n relabel(D, F),\n B =.. [E|F].\n\ndynify(A) :-\n var(A),\n !.\ndynify((A, B)) :-\n !,\n dynify(A),\n dynify(B).\ndynify(implies(A, B, _)) :-\n !,\n dynify(A),\n dynify(B).\ndynify(':-'(A, B)) :-\n !,\n dynify(A),\n dynify(B).\ndynify(answer(A, _, _)) :-\n nonvar(A),\n !,\n ( current_predicate(A/2)\n -> true\n ; dynamic(A/2)\n ).\ndynify('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(_, A)) :-\n !,\n dynify(A).\ndynify('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, A)) :-\n !,\n dynify(A).\ndynify('<http://www.w3.org/2000/10/swap/log#onNeutralSurface>'(_, A)) :-\n !,\n dynify(A).\ndynify('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(_, A)) :-\n !,\n dynify(A).\ndynify(A) :-\n functor(A, F, N),\n ( current_predicate(F/N)\n -> true\n ; dynamic(F/N)\n ).\n\nconjify((A, B), (C, D)) :-\n !,\n conjify(A, C),\n conjify(B, D).\nconjify('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'([literal(when, type('<http://www.w3.org/2001/XMLSchema#string>')),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], true), C], true), when(D, C)) :-\n !,\n D =.. [A|B].\nconjify('<http://eulersharp.sourceforge.net/2003/03swap/prolog#cut>'([], true), !) :-\n !.\nconjify('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'([literal(!, type('<http://www.w3.org/2001/XMLSchema#string>'))], true), !) :-\n !.\nconjify(A, A).\n\natomify(A, A) :-\n var(A),\n !.\natomify([A|B], [C|D]) :-\n !,\n atomify(A, C),\n atomify(B, D).\natomify(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), A) :-\n atom(A),\n !.\natomify(A, A).\n\ncommonvars('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(A, _), B, C) :-\n !,\n commonvars(A, B, C).\ncommonvars(A, B, C) :-\n term_variables(A, D),\n term_variables(B, E),\n copy_term_nat([D, E], [F, G]),\n labelvars([F, G], 0, _),\n findall(H,\n ( member(H, F),\n member(H, G)\n ),\n C\n ).\n\ngetvars(A, B) :-\n findvars(A, C, alpha),\n distinct(C, B).\n\nmakevars(A, B, beta(C)) :-\n !,\n distinct(C, D),\n findvars(D, G, beta),\n ( D \\= G\n -> throw(invalid_graffiti(D, in(A)))\n ; true\n ),\n length(D, E),\n length(F, E),\n makevars(A, B, D, F).\nmakevars(A, B, Z) :-\n findvars(A, C, Z),\n distinct(C, D),\n length(D, E),\n length(F, E),\n makevars(A, B, D, F).\n\nmakevars(A, B, C, D) :-\n atomic(A),\n !,\n ( atom(A),\n nth0(E, C, A)\n -> nth0(E, D, B)\n ; B = A\n ).\nmakevars(A, A, _, _) :-\n var(A),\n !.\nmakevars([], [], _, _) :-\n !.\nmakevars([A|B], [C|D], E, F) :-\n makevars(A, C, E, F),\n makevars(B, D, E, F),\n !.\nmakevars(A, B, E, F) :-\n A =.. C,\n makevars(C, [Dh|Dt], E, F),\n nonvar(Dh),\n B =.. [Dh|Dt].\n\nfindvars(A, B, Z) :-\n atomic(A),\n !,\n ( atom(A),\n findvar(A, Z)\n -> B = [A]\n ; B = []\n ).\nfindvars(A, [], _) :-\n var(A),\n !.\nfindvars([], [], _) :-\n !.\nfindvars([A|B], C, Z) :-\n findvars(A, D, Z),\n findvars(B, E, Z),\n append(D, E, C),\n !.\nfindvars(A, B, Z) :-\n A =.. C,\n findvars(C, B, Z).\n\nshallowvars(A, B, Z) :-\n atomic(A),\n !,\n ( atom(A),\n findvar(A, Z)\n -> B = [A]\n ; B = []\n ).\nshallowvars(A, [], _) :-\n var(A),\n !.\nshallowvars([], [], _) :-\n !.\nshallowvars([A|B], C, Z) :-\n shallowvars(A, D, Z),\n shallowvars(B, E, Z),\n append(D, E, C),\n !.\nshallowvars(_, [], _).\n\nfindvar(A, alpha) :-\n !,\n atom_concat('<http://eyereasoner.github.io/var#', _, A).\nfindvar(A, beta) :-\n !,\n ( sub_atom(A, 0, _, _, '_bn_')\n ; sub_atom(A, 0, _, _, '_e_')\n ; sub_atom(A, _, 19, _, '/.well-known/genid/')\n ; sub_atom(A, 0, _, _, some)\n ; sub_atom(A, 0, _, _, '_:')\n ).\nfindvar(A, delta) :-\n !,\n ( sub_atom(A, _, 19, _, '/.well-known/genid/')\n ; sub_atom(A, 0, _, _, some)\n ).\nfindvar(A, epsilon) :-\n !,\n sub_atom(A, 0, 1, _, '_'),\n \\+ sub_atom(A, 0, _, _, '_bn_'),\n \\+ sub_atom(A, 0, _, _, '_e_').\nfindvar(A, zeta) :-\n sub_atom(A, 0, _, _, some),\n !.\nfindvar(A, eta) :-\n sub_atom(A, 0, _, _, allv).\n\nraw_type(A, '<http://www.w3.org/1999/02/22-rdf-syntax-ns#List>') :-\n is_list(A),\n !.\nraw_type(A, '<http://www.w3.org/2000/10/swap/log#Literal>') :-\n number(A),\n !.\nraw_type(A, '<http://www.w3.org/2000/10/swap/log#Literal>') :-\n atom(A),\n \\+ sub_atom(A, 0, _, _, some),\n \\+ sub_atom(A, 0, _, _, avar),\n \\+ (sub_atom(A, 0, 1, _, '<'), sub_atom(A, _, 1, 0, '>')),\n !.\nraw_type(literal(_, _), '<http://www.w3.org/2000/10/swap/log#Literal>') :-\n !.\nraw_type(rdiv(_, _), '<http://www.w3.org/2000/10/swap/log#Literal>') :-\n !.\nraw_type('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#epsilon>', '<http://www.w3.org/2000/10/swap/log#Literal>') :-\n !.\nraw_type((_, _), '<http://www.w3.org/2000/10/swap/log#Formula>') :-\n !.\nraw_type(set(_), '<http://www.w3.org/2000/10/swap/log#Set>') :-\n !.\nraw_type(A, '<http://www.w3.org/2000/10/swap/log#Formula>') :-\n functor(A, B, C),\n B \\= ':',\n C >= 2,\n !.\nraw_type(_, '<http://www.w3.org/2000/10/swap/log#Other>').\n\ngetnumber(rdiv(A, B), C) :-\n nonvar(A),\n !,\n C is A/B.\ngetnumber(A, A) :-\n number(A),\n !.\ngetnumber(A, epsilon) :-\n nonvar(A),\n A = '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#epsilon>',\n !.\ngetnumber(A, A) :-\n nonvar(A),\n memberchk(A, [inf, -inf, nan]),\n !.\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n datetime(B, C, []).\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n date(B, C, []).\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n time(B, C, []).\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#duration>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n duration(B, C, []).\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n yearmonthduration(B, C, []).\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n daytimeduration(B, C, []).\ngetnumber(literal(A, _), B) :-\n ground(A),\n atom_codes(A, C),\n numeral(C, D),\n catch(number_codes(B, D), _, fail).\n\ngetint(A, B) :-\n getnumber(A, C),\n B is integer(round(C)).\n\ngetbool(literal(false, type('<http://www.w3.org/2001/XMLSchema#boolean>')), false).\ngetbool(literal(true, type('<http://www.w3.org/2001/XMLSchema#boolean>')), true).\ngetbool(literal('0', type('<http://www.w3.org/2001/XMLSchema#boolean>')), false).\ngetbool(literal('1', type('<http://www.w3.org/2001/XMLSchema#boolean>')), true).\ngetbool(false, false).\ngetbool(true, true).\n\ngetlist(A, A) :-\n var(A),\n !.\ngetlist(set(A), A) :-\n !.\ngetlist('<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>', []) :-\n !.\ngetlist([], []) :-\n !.\ngetlist([A|B], [C|D]) :-\n getlist(A, C),\n !,\n getlist(B, D).\ngetlist([A|B], [A|D]) :-\n !,\n getlist(B, D).\ngetlist(A, [B|C]) :-\n '<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>'(A, B),\n '<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'(A, D),\n getlist(D, C).\n\ngetstring(A, B) :-\n '<http://www.w3.org/2000/10/swap/log#uri>'(A, B),\n !.\ngetstring(A, A).\n\ngetcodes(literal(A, _), B) :-\n nonvar(A),\n !,\n atom_codes(A, B).\ngetcodes(A, B) :-\n nonvar(A),\n with_output_to_chars(wg(A), B).\n\npreformat([], []) :-\n !.\npreformat([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], [A|D]) :-\n !,\n preformat(B, D).\npreformat([A|B], [A|D]) :-\n preformat(B, D).\n\nnumeral([0'-, 0'.|A], [0'-, 0'0, 0'.|A]) :-\n !.\nnumeral([0'+, 0'.|A], [0'+, 0'0, 0'.|A]) :-\n !.\nnumeral([0'.|A], [0'0, 0'.|A]) :-\n !.\nnumeral(A, B) :-\n append([C, [0'., 0'e], D], A),\n append([C, [0'., 0'0, 0'e], D], B),\n !.\nnumeral(A, B) :-\n append([C, [0'., 0'E], D], A),\n append([C, [0'., 0'0, 0'E], D], B),\n !.\nnumeral(A, B) :-\n last(A, 0'.),\n append(A, [0'0], B),\n !.\nnumeral(A, A).\n\nrdiv_codes(rdiv(A, B), C) :-\n append(D, [0'.|E], C),\n append(D, E, F),\n number_codes(A, F),\n lzero(E, G),\n number_codes(B, [0'1|G]),\n !.\nrdiv_codes(rdiv(A, 1), C) :-\n number_codes(A, C).\n\nlzero([], []) :-\n !.\nlzero([_|A], [0'0|B]) :-\n lzero(A, B).\n\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), C], B) :-\n nonvar(C),\n '<http://www.w3.org/2000/01/rdf-schema#subClassOf>'(C, '<http://www.w3.org/2001/XMLSchema#integer>'),\n integer(B),\n !,\n atom_number(A, B).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#integer>'], B) :-\n integer(B),\n !,\n atom_number(A, B).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#double>'], B) :-\n float(B),\n !,\n atom_number(A, B).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#dateTime>'], B) :-\n ( number(B)\n -> datetime(B, C)\n ; nonvar(B),\n B = date(Year, Month, Day, Hour, Minute, Second, Offset, _, _),\n datetime(Year, Month, Day, Hour, Minute, Second, Offset, C)\n ),\n !,\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#date>'], B) :-\n ( number(B)\n -> date(B, C)\n ; nonvar(B),\n B = date(Year, Month, Day, _, _, _, Offset, _, _),\n date(Year, Month, Day, Offset, C)\n ),\n !,\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#time>'], B) :-\n ( number(B)\n -> time(B, C)\n ; nonvar(B),\n B = date(_, _, _, Hour, Minute, Second, Offset, _, _),\n time(Hour, Minute, Second, Offset, C)\n ),\n !,\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#duration>'], B) :-\n number(B),\n !,\n daytimeduration(B, C),\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'], B) :-\n number(B),\n !,\n yearmonthduration(B, C),\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'], B) :-\n number(B),\n !,\n daytimeduration(B, C),\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#boolean>'], A) :-\n atomic(A),\n getbool(A, A),\n !.\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), prolog:atom], A) :-\n atomic(A),\n \\+ (sub_atom(A, 0, 1, _, '<'), sub_atom(A, _, 1, 0, '>')),\n !.\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>'], literal(A, lang(_))) :-\n !.\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), B], literal(A, type(B))).\n\nhash_to_ascii([], L1, L1).\nhash_to_ascii([A|B], [C, D|L3], L4) :-\n E is A>>4 /\\ 15,\n F is A /\\ 15,\n code_type(C, xdigit(E)),\n code_type(D, xdigit(F)),\n hash_to_ascii(B, L3, L4).\n\nmemotime(datime(A, B, C, D, E, F), G) :-\n ( mtime(datime(A, B, C, D, E, F), G)\n -> true\n ; catch(date_time_stamp(date(A, B, C, D, E, F, 0, -, -), H), _, fail),\n fmsec(F, H, G),\n assertz(mtime(datime(A, B, C, D, E, F), G))\n ).\n\ndatetime(A, L1, L13) :-\n int(B, L1, [0'-|L3]),\n int(C, L3, [0'-|L5]),\n int(D, L5, [0'T|L7]),\n int(E, L7, [0':|L9]),\n int(F, L9, [0':|L11]),\n decimal(G, L11, L12),\n timezone(H, L12, L13),\n I is -H,\n catch(date_time_stamp(date(B, C, D, E, F, G, I, -, -), J), _, fail),\n fmsec(G, J, A).\n\ndatetime(A, B, C, D, E, F, G, L1, L13) :-\n int(A, L1, [0'-|L3]),\n int(B, L3, [0'-|L5]),\n int(C, L5, [0'T|L7]),\n int(D, L7, [0':|L9]),\n int(E, L9, [0':|L11]),\n decimal(F, L11, L12),\n timezone(G, L12, L13).\n\ndate(A, L1, L7) :-\n int(B, L1, [0'-|L3]),\n int(C, L3, [0'-|L5]),\n int(D, L5, L6),\n timezone(H, L6, L7),\n I is -H,\n catch(date_time_stamp(date(B, C, D, 0, 0, 0, I, -, -), E), _, fail),\n fmsec(0, E, A).\n\ndate(A, B, C, D, L1, L7) :-\n int(A, L1, [0'-|L3]),\n int(B, L3, [0'-|L5]),\n int(C, L5, L6),\n timezone(D, L6, L7).\n\ntime(A, L1, L7) :-\n int(B, L1, [0':|L3]),\n int(C, L3, [0':|L5]),\n decimal(D, L5, L6),\n timezone(E, L6, L7),\n ( B = 24\n -> A is C*60+D-E\n ; A is B*3600+C*60+D-E\n ).\n\ntime(A, B, C, D, L1, L7) :-\n int(A, L1, [0':|L3]),\n int(B, L3, [0':|L5]),\n decimal(C, L5, L6),\n timezone(D, L6, L7).\n\nduration(A, L1, L7) :-\n dsign(B, L1, [0'P|L3]),\n years(C, L3, L4),\n months(D, L4, L5),\n days(E, L5, L6),\n dtime(F, L6, L7),\n A is B*(C*31556952+D*2629746+E*86400.0+F).\n\nyearmonthduration(A, L1, L5) :-\n dsign(B, L1, [0'P|L3]),\n years(C, L3, L4),\n months(D, L4, L5),\n A is B*(C*12+D).\n\ndaytimeduration(A, L1, L5) :-\n dsign(B, L1, [0'P|L3]),\n days(C, L3, L4),\n dtime(D, L4, L5),\n A is B*(C*86400.0+D).\n\ntimezone(A, L1, L4) :-\n int(B, L1, [0':|L3]),\n !,\n int(C, L3, L4),\n A is B*3600+C*60.\ntimezone(0, [0'Z|L2], L2) :-\n !.\ntimezone(0, L1, L1).\n\ndsign(1, [0'+|L2], L2).\ndsign(-1, [0'-|L2], L2).\ndsign(1, L1, L1).\n\ndtime(A, [0'T|L2], L5) :-\n !,\n hours(B, L2, L3),\n minutes(C, L3, L4),\n seconds(D, L4, L5),\n A is B*3600+C*60+D.\ndtime(0, L1, L1).\n\nyears(A, L1, L3) :-\n int(A, L1, [0'Y|L3]).\nyears(0, L1, L1).\n\nmonths(A, L1, L3) :-\n int(A, L1, [0'M|L3]).\nmonths(0, L1, L1) .\n\ndays(A, L1, L3) :-\n int(A, L1, [0'D|L3]).\ndays(0, L1, L1).\n\nhours(A, L1, L3) :-\n int(A, L1, [0'H|L3]).\nhours(0, L1, L1).\n\nminutes(A, L1, L3) :-\n int(A, L1, [0'M|L3]).\nminutes(0, L1, L1).\n\nseconds(A, L1, L3) :-\n decimal(A, L1, [0'S|L3]).\nseconds(0, L1, L1).\n\nint(A, L1, L4) :-\n sgn(B, L1, L2),\n digit(C, L2, L3),\n digits(D, L3, L4),\n number_codes(A, [B, C|D]).\n\ndecimal(A, L1, L5) :-\n sgn(B, L1, L2),\n digit(C, L2, L3),\n digits(D, L3, L4),\n fraction(E, L4, L5),\n append([B, C|D], E, F),\n number_codes(A, F).\n\nsgn(0'+, [0'+|L2], L2).\nsgn(0'-, [0'-|L2], L2).\nsgn(0'+, L1, L1).\n\nfraction([0'., A|B], [0'.|L2], L4) :-\n !,\n digit(A, L2, L3),\n digits(B, L3, L4).\nfraction([], L1, L1).\n\ndigits([A|B], L1, L3) :-\n digit(A, L1, L2),\n digits(B, L2, L3).\ndigits([], L1, L1).\n\ndigit(A, [A|L2], L2) :-\n code_type(A, digit).\n\nfmsec(A, B, C) :-\n integer(A),\n !,\n C is floor(B).\nfmsec(_, B, B).\n\ndatetime(A, B) :-\n stamp_date_time(A, date(Year, Month, Day, Hour, Minute, Second, _, _, _), 0),\n fmsec(A, Second, Sec),\n ycodes(Year, C),\n ncodes(Month, D),\n ncodes(Day, E),\n ncodes(Hour, F),\n ncodes(Minute, G),\n ncodes(Sec, H),\n append([C, [0'-], D, [0'-], E, [0'T], F, [0':], G, [0':], H, [0'Z]], B).\n\ndatetime(Year, Month, Day, Hour, Minute, Second, Offset, B) :-\n ycodes(Year, C),\n ncodes(Month, D),\n ncodes(Day, E),\n ncodes(Hour, F),\n ncodes(Minute, G),\n ncodes(Second, H),\n ( Offset =:= 0\n -> append([C, [0'-], D, [0'-], E, [0'T], F, [0':], G, [0':], H, [0'Z]], B)\n ; ( Offset > 0\n -> I = [0'-],\n OHour is Offset//3600\n ; I = [0'+],\n OHour is -Offset//3600\n ),\n ncodes(OHour, J),\n OMinute is (Offset mod 3600)//60,\n ncodes(OMinute, K),\n append([C, [0'-], D, [0'-], E, [0'T], F, [0':], G, [0':], H, I, J, [0':], K], B)\n ).\n\ndate(A, B) :-\n N is A+3600*12,\n stamp_date_time(N, date(Year, Month, Day, _, _, _, _, _, _), 0),\n ycodes(Year, C),\n ncodes(Month, D),\n ncodes(Day, E),\n Offset is (round(floor(N)) mod 86400) - 3600*12,\n ( Offset =:= 0\n -> append([C, [0'-], D, [0'-], E, [0'Z]], B)\n ; ( Offset > 0\n -> I = [0'-],\n OHour is Offset//3600\n ; I = [0'+],\n OHour is -Offset//3600\n ),\n ncodes(OHour, J),\n OMinute is (Offset mod 3600)//60,\n ncodes(OMinute, K),\n append([C, [0'-], D, [0'-], E, I, J, [0':], K], B)\n ).\n\ndate(Year, Month, Day, Offset, B) :-\n ycodes(Year, C),\n ncodes(Month, D),\n ncodes(Day, E),\n ( Offset =:= 0\n -> append([C, [0'-], D, [0'-], E, [0'Z]], B)\n ; ( Offset > 0\n -> I = [0'-],\n OHour is Offset//3600\n ; I = [0'+],\n OHour is -Offset//3600\n ),\n ncodes(OHour, J),\n OMinute is (Offset mod 3600)//60,\n ncodes(OMinute, K),\n append([C, [0'-], D, [0'-], E, I, J, [0':], K], B)\n ).\n\ntime(A, B) :-\n stamp_date_time(A, date(_, _, _, Hour, Minute, Second, _, _, _), 0),\n fmsec(A, Second, Sec),\n ncodes(Hour, F),\n ncodes(Minute, G),\n ncodes(Sec, H),\n append([F, [0':], G, [0':], H, [0'Z]], B).\n\ntime(Hour, Minute, Second, Offset, B) :-\n ncodes(Hour, F),\n ncodes(Minute, G),\n ncodes(Second, H),\n ( Offset =:= 0\n -> append([F, [0':], G, [0':], H, [0'Z]], B)\n ; ( Offset > 0\n -> I = [0'-],\n OHour is Offset//3600\n ; I = [0'+],\n OHour is -Offset//3600\n ),\n ncodes(OHour, J),\n OMinute is (Offset mod 3600)//60,\n ncodes(OMinute, K),\n append([F, [0':], G, [0':], H, I, J, [0':], K], B)\n ).\n\nyearmonthduration(A, B) :-\n ( A < 0\n -> C = [0'-]\n ; C = []\n ),\n D is abs(A),\n E is D//12,\n number_codes(E, Years),\n F is D-(D//12)*12,\n number_codes(F, Months),\n append([C, [0'P], Years, [0'Y], Months, [0'M]], B).\n\ndaytimeduration(A, B) :-\n AInt is round(floor(A)),\n AFrac is A-AInt,\n ( AInt < 0\n -> C = [0'-]\n ; C = []\n ),\n D is abs(AInt),\n E is D//86400,\n number_codes(E, Days),\n F is (D-(D//86400)*86400)//3600,\n number_codes(F, Hours),\n G is (D-(D//3600)*3600)//60,\n number_codes(G, Minutes),\n H is D-(D//60)*60+AFrac,\n number_codes(H, Seconds),\n append([C, [0'P| Days], [0'D, 0'T| Hours], [0'H| Minutes], [0'M| Seconds], [0'S]], B).\n\nncodes(A, B) :-\n number_codes(A, D),\n ( A < 10\n -> B = [0'0| D]\n ; B = D\n ).\n\nycodes(A, B) :-\n C is abs(A),\n number_codes(C, D),\n ( C < 10\n -> E = [0'0, 0'0, 0'0| D]\n ; ( C < 100\n -> E = [0'0, 0'0| D]\n ; ( C < 1000\n -> E = [0'0| D]\n ; E = D\n )\n )\n ),\n ( A >= 0\n -> B = E\n ; B = [0'-|E]\n ).\n\nabsolute_uri('-', '-') :-\n !.\nabsolute_uri(A, B) :-\n ( is_absolute_url(A)\n -> B = A\n ; absolute_file_name(A, C),\n prolog_to_os_filename(D, C),\n atom_codes(D, E),\n subst([[[0x20], [0'%, 0'2, 0'0]]], E, F),\n atom_codes(G, F),\n atomic_list_concat(['file://', G], B)\n ).\n\nresolve_uri(A, _, A) :-\n sub_atom(A, _, 1, _, ':'),\n !.\nresolve_uri('', A, A) :-\n !.\nresolve_uri('#', A, B) :-\n !,\n atomic_list_concat([A, '#'], B).\nresolve_uri(A, B, A) :-\n \\+sub_atom(B, _, 1, _, ':'),\n !.\nresolve_uri(A, B, C) :-\n so_uri(U),\n atom_length(U, V),\n sub_atom(A, 0, 1, _, '#'),\n sub_atom(B, 0, V, _, U),\n !,\n atomic_list_concat([B, A], C).\nresolve_uri(A, B, C) :-\n sub_atom(A, 0, 2, _, './'),\n !,\n sub_atom(A, 2, _, 0, R),\n resolve_uri(R, B, C).\nresolve_uri(A, B, C) :-\n sub_atom(A, 0, 3, _, '../'),\n !,\n sub_atom(A, 3, _, 0, R),\n so_uri(U),\n atom_length(U, V),\n sub_atom(B, 0, V, D, U),\n sub_atom(B, V, D, _, E),\n ( sub_atom(E, F, 1, G, '/'),\n sub_atom(E, _, G, 0, H),\n \\+sub_atom(H, _, _, _, '/'),\n K is V+F\n -> sub_atom(B, 0, K, _, S)\n ; S = B\n ),\n resolve_uri(R, S, C).\nresolve_uri(A, B, C) :-\n so_uri(U),\n atom_length(U, V),\n sub_atom(A, 0, 1, _, '/'),\n sub_atom(B, 0, V, D, U),\n sub_atom(B, V, D, _, E),\n ( sub_atom(E, F, 1, _, '/')\n -> sub_atom(E, 0, F, _, G)\n ; G = E\n ),\n !,\n atomic_list_concat([U, G, A], C).\nresolve_uri(A, B, C) :-\n so_uri(U),\n atom_length(U, V),\n sub_atom(B, 0, V, D, U),\n sub_atom(B, V, D, _, E),\n ( sub_atom(E, F, 1, G, '/'),\n sub_atom(E, _, G, 0, H),\n \\+sub_atom(H, _, _, _, '/')\n -> sub_atom(E, 0, F, _, I)\n ; I = E\n ),\n !,\n atomic_list_concat([U, I, '/', A], C).\nresolve_uri(A, _, _) :-\n nb_getval(line_number, Ln),\n throw(unresolvable_relative_uri(A, after_line(Ln))).\n\nso_uri('http://').\nso_uri('https://').\nso_uri('ftp://').\nso_uri('file://').\n\nwcacher(A, B) :-\n wcache(A, B),\n !.\nwcacher(A, B) :-\n wcache(C, D),\n sub_atom(A, 0, I, _, C),\n sub_atom(A, I, _, 0, E),\n atomic_list_concat([D, E], B).\n\nprolog_verb(S, Name) :-\n ( atom(S),\n atom_concat('\\'<http://eulersharp.sourceforge.net/2003/03swap/prolog#', A, S),\n atom_concat(B, '>\\'', A)\n -> ( B = conjunction\n -> Pred = '\\', \\''\n ; ( B = disjunction\n -> Pred = '\\';\\''\n ; ( prolog_sym(B, Pred, _)\n -> true\n ; nb_getval(line_number, Ln),\n throw(invalid_prolog_builtin(B, after_line(Ln)))\n )\n )\n ),\n Name = prolog:Pred\n ; Name = S\n ).\n\ntimestamp(Stamp) :-\n get_time(StampN),\n datetime(StampN, StampC),\n atom_codes(StampA, StampC),\n ( sub_atom(StampA, I, 1, 0, 'Z'),\n I > 23\n -> sub_atom(StampA, 0, 23, _, StampB),\n atomic_list_concat([StampB, 'Z'], Stamp)\n ; Stamp = StampA\n ).\n\n%\n% Regular expressions\n%\n\n% Regular Expressions inspired by http://www.cs.sfu.ca/~cameron/Teaching/384/99-3/regexp-plg.html\nregex(RE_esc_atom, Input_esc_atom, Output_esc_atoms) :-\n atom_codes(RE_esc_atom, RE_esc),\n atom_codes(Input_esc_atom, Input_esc),\n escape_string(RE, RE_esc),\n re(Parsed_RE, RE, []),\n ( RE = [0'^|_]\n -> Bos = true\n ; Bos = false\n ),\n escape_string(Input, Input_esc),\n tokenize2(Parsed_RE, Input, Outputs, Bos),\n findall(Output_esc_atom,\n ( member(Output, Outputs),\n escape_string(Output, Output_esc),\n atom_codes(Output_esc_atom, Output_esc)\n ),\n Output_esc_atoms\n ),\n !.\n\ntokenize2(_P_RE, [], [], true).\ntokenize2(P_RE, Input, Output, Bos) :-\n ( rematch1(P_RE, Input, _, Output)\n -> true\n ; Bos = false,\n Input = [_|Inp],\n tokenize2(P_RE, Inp, Output, Bos)\n ).\n\nrematch1(union(RE1, _RE2), S, U, Selected) :-\n rematch1(RE1, S, U, Selected).\nrematch1(union(_RE1, RE2), S, U, Selected) :-\n rematch1(RE2, S, U, Selected).\nrematch1(conc(RE1, RE2), S, U, Selected) :-\n rematch1(RE1, S, U1, Sel1),\n rematch1(RE2, U1, U, Sel2),\n append(Sel1, Sel2, Selected).\nrematch1(star(RE), S, U, Selected) :-\n rematch1(RE, S, U1, Sel1),\n rematch1(star(RE), U1, U, Sel2),\n append(Sel1, Sel2, Selected).\nrematch1(star(_RE), S, S, []).\nrematch1(qm(RE), S, U, Selected) :-\n rematch1(RE, S, U, Selected).\nrematch1(qm(_RE), S, S, []).\nrematch1(plus(RE), S, U, Selected) :-\n rematch1(RE, S, U1, Sel1),\n rematch1(star(RE), U1, U, Sel2),\n append(Sel1, Sel2, Selected).\nrematch1(group(RE), S, U, Selected) :-\n rematch1(RE, S, U, Sel1),\n append(P, U, S),\n append(Sel1, [P], Selected).\nrematch1(any, [_C1|U], U, []).\nrematch1(char(C), [C|U], U, []).\nrematch1(bos, S, S, []).\nrematch1(eos, [], [], []).\nrematch1(negSet(Set), [C|U], U, []) :-\n \\+charSetMember(C, Set).\nrematch1(posSet(Set), [C|U], U, []) :-\n charSetMember(C, Set).\n\ncharSetMember(C, [char(C)|_]).\ncharSetMember(C, [range(C1, C2)|_]) :-\n C1 =< C,\n C =< C2.\ncharSetMember(C, [negSet(Set)|_]) :-\n \\+charSetMember(C, Set).\ncharSetMember(C, [posSet(Set)|_]) :-\n charSetMember(C, Set).\ncharSetMember(C, [_|T]) :-\n charSetMember(C, T).\n\nre(Z, L1, L3) :-\n basicRE(W, L1, L2),\n reTail(W, Z, L2, L3).\n\nreTail(W, Z, [0'||L2], L4) :-\n basicRE(X, L2, L3),\n reTail(union(W, X), Z, L3, L4).\nreTail(W, W, L1, L1).\n\nbasicRE(Z, L1, L3) :-\n simpleRE(W, L1, L2),\n basicREtail(W, Z, L2, L3).\n\nbasicREtail(W, Z, L1, L3) :-\n simpleRE(X, L1, L2),\n basicREtail(conc(W, X), Z, L2, L3).\nbasicREtail(W, W, L1, L1).\n\nsimpleRE(Z, L1, L3) :-\n elementalRE(W, L1, L2),\n simpleREtail(W, Z, L2, L3).\n\nsimpleREtail(W, star(W), [0'*|L2], L2).\nsimpleREtail(W, qm(W), [0'?|L2], L2).\nsimpleREtail(W, plus(W), [0'+|L2], L2).\nsimpleREtail(W, W, L1, L1).\n\nelementalRE(any, [0'.|L2], L2).\nelementalRE(group(X), [0'(|L2], L4) :-\n re(X, L2, [0')|L4]).\nelementalRE(bos, [0'^|L2], L2).\nelementalRE(eos, [0'$|L2], L2).\nelementalRE(posSet([range(0'A, 0'Z), range(0'a, 0'z), range(0'0, 0'9), char(0'_)]), [0'\\\\, 0'w|L2], L2).\nelementalRE(negSet([range(0'A, 0'Z), range(0'a, 0'z), range(0'0, 0'9), char(0'_)]), [0'\\\\, 0'W|L2], L2).\nelementalRE(posSet([range(0'0, 0'9)]), [0'\\\\, 0'd|L2], L2).\nelementalRE(negSet([range(0'0, 0'9)]), [0'\\\\, 0'D|L2], L2).\nelementalRE(posSet([char(0x20), char(0'\\t), char(0'\\r), char(0'\\n), char(0'\\v), char(0'\\f)]), [0'\\\\, 0's|L2], L2).\nelementalRE(negSet([char(0x20), char(0'\\t), char(0'\\r), char(0'\\n), char(0'\\v), char(0'\\f)]), [0'\\\\, 0'S|L2], L2).\nelementalRE(char(C), [0'\\\\, C|L2], L2) :-\n re_metachar([C]).\nelementalRE(char(C), [C|L2], L2) :-\n \\+re_metachar([C]).\nelementalRE(negSet(X), [0'[, 0'^|L2], L4) :-\n !,\n setItems(X, L2, [0']|L4]).\nelementalRE(posSet(X), [0'[|L2], L4) :-\n setItems(X, L2, [0']|L4]).\n\nre_metachar([0'\\\\]).\nre_metachar([0'|]).\nre_metachar([0'*]).\nre_metachar([0'?]).\nre_metachar([0'+]).\nre_metachar([0'.]).\nre_metachar([0'[]).\nre_metachar([0'$]).\nre_metachar([0'(]).\nre_metachar([0')]).\n\nsetItems([Item1|MoreItems], L1, L3) :-\n setItem(Item1, L1, L2),\n setItems(MoreItems, L2, L3).\nsetItems([Item1], L1, L2) :-\n setItem(Item1, L1, L2).\n\nsetItem(posSet([range(0'A, 0'Z), range(0'a, 0'z), range(0'0, 0'9), char(0'_)]), [0'\\\\, 0'w|L2], L2).\nsetItem(negSet([range(0'A, 0'Z), range(0'a, 0'z), range(0'0, 0'9), char(0'_)]), [0'\\\\, 0'W|L2], L2).\nsetItem(posSet([range(0'0, 0'9)]), [0'\\\\, 0'd|L2], L2).\nsetItem(negSet([range(0'0, 0'9)]), [0'\\\\, 0'D|L2], L2).\nsetItem(posSet([char(0x20), char(0'\\t), char(0'\\r), char(0'\\n), char(0'\\v), char(0'\\f)]), [0'\\\\, 0's|L2], L2).\nsetItem(negSet([char(0x20), char(0'\\t), char(0'\\r), char(0'\\n), char(0'\\v), char(0'\\f)]), [0'\\\\, 0'S|L2], L2).\nsetItem(char(C), [0'\\\\, C|L2], L2) :-\n set_metachar([C]).\nsetItem(char(C), [C|L2], L2) :-\n \\+set_metachar([C]).\nsetItem(range(A, B), L1, L4) :-\n setItem(char(A), L1, [0'-|L3]),\n setItem(char(B), L3, L4).\n\nset_metachar([0'\\\\]).\nset_metachar([0']]).\nset_metachar([0'-]).\n\nregexp_wildcard([], []) :-\n !.\nregexp_wildcard([0'*|A], [0'., 0'*|B]) :-\n !,\n regexp_wildcard(A, B).\nregexp_wildcard([A|B], [A|C]) :-\n regexp_wildcard(B, C).\n\nfm(A) :-\n format(user_error, '~n*** ~q~n', [A]),\n flush_output(user_error).\n\nmf(A) :-\n forall(\n catch(A, _, fail),\n ( portray_clause(user_error, A),\n write(user_error, '\\n')\n )\n ),\n flush_output(user_error).\n";
4
+ var eye = "% --------------------------------------------\n% Euler Yet another proof Engine -- Jos De Roo\n% --------------------------------------------\n%\n% See http://github.com/eyereasoner/eye\n%\n\n:- use_module(library(lists)).\n:- use_module(library(gensym)).\n:- use_module(library(system)).\n:- use_module(library(terms)).\n:- use_module(library(url)).\n:- use_module(library(charsio)).\n:- use_module(library(qsave)).\n:- use_module(library(base64)).\n:- use_module(library(date)).\n:- use_module(library(prolog_jiti)).\n:- use_module(library(sha)).\n:- use_module(library(semweb/turtle)).\n:- catch(use_module(library(http/http_open)), _, true).\n\nversion_info('EYE v23.107.1316 josd').\n\nlicense_info('MIT License\n\nCopyright (c) 2006-2022 Jos De Roo\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.').\n\nhelp_info('Usage: eye <options>* <data>* <query>*\neye\n swipl -g main eye.pl --\n<options>\n --blogic support RDF surfaces\n --csv-separator <separator> CSV separator such as , or ;\n --debug output debug info on stderr\n --debug-cnt output debug info about counters on stderr\n --debug-djiti output debug info about DJITI on stderr\n --debug-implies output debug info about implies on stderr\n --debug-models output debug info about models on stderr\n --debug-pvm output debug info about PVM code on stderr\n --help show help info\n --hmac-key <key> HMAC key used in e:hmac-sha built-in\n --ignore-inference-fuse do not halt in case of inference fuse\n --image <pvm-file> output all <data> and all code to <pvm-file>\n --intermediate <n3p-file> output all <data> to <n3p-file>\n --license show license info\n --max-inferences <nr> halt after maximum number of inferences\n --multi-query go into query answer loop\n --no-distinct-input no distinct triples in the input\n --no-distinct-output no distinct answers in the output\n --no-erase no erase functionality for blogic\n --no-numerals no numerals in the output\n --no-qnames no qnames in the output\n --no-qvars no qvars in the output\n --no-ucall no extended unifier for forward rules\n --nope no proof explanation\n --output <file> output reasoner output to <file>\n --profile output profile info on stderr\n --quantify <prefix> quantify uris with <prefix> in the output\n --quiet quiet mode\n --random-seed create random seed for e:random built-in\n --restricted restricting to core built-ins\n --rule-histogram output rule histogram info on stderr\n --skolem-genid <genid> use <genid> in Skolem IRIs\n --source <file> read command line arguments from <file>\n --statistics output statistics info on stderr\n --strings output log:outputString objects on stdout\n --tactic limited-answer <nr> give only a limited number of answers\n --tactic linear-select select each rule only once\n --version show version info\n --warn output warning info on stderr\n --wcache <uri> <file> to tell that <uri> is cached as <file>\n<data>\n [--n3] <uri> N3 triples and rules\n --n3p <uri> N3P intermediate\n --proof <uri> N3 proof lemmas\n --turtle <uri> Turtle triples\n<query>\n --entail <rdf-graph> output true if RDF graph is entailed\n --not-entail <rdf-graph> output true if RDF graph is not entailed\n --pass output deductive closure\n --pass-all output deductive closure plus rules\n --pass-all-ground ground the rules and run --pass-all\n --pass-only-new output only new derived triples\n --query <n3-query> output filtered with filter rules').\n\n:- dynamic(answer/3). % answer(Predicate, Subject, Object)\n:- dynamic(argi/1).\n:- dynamic(base_uri/1).\n:- dynamic(bcnd/2).\n:- dynamic(bgot/3).\n:- dynamic(brake/0).\n:- dynamic(bref/2).\n:- dynamic(bvar/1).\n:- dynamic(cc/1).\n:- dynamic(cpred/1).\n:- dynamic(data_fuse/0).\n:- dynamic(evar/3).\n:- dynamic(exopred/3). % exopred(Predicate, Subject, Object)\n:- dynamic(fact/1).\n:- dynamic(flag/1).\n:- dynamic(flag/2).\n:- dynamic(fpred/1).\n:- dynamic(got_dq/0).\n:- dynamic(got_head/0).\n:- dynamic(got_labelvars/3).\n:- dynamic(got_models/0).\n:- dynamic(got_pi/0).\n:- dynamic(got_random/3).\n:- dynamic(got_sq/0).\n:- dynamic(got_unique/2).\n:- dynamic(got_wi/5). % got_wi(Source, Premise, Premise_index, Conclusion, Rule)\n:- dynamic(got_uuid/1).\n:- dynamic(graph/2).\n:- dynamic(hash_value/2).\n:- dynamic(implies/3). % implies(Premise, Conclusion, Source)\n:- dynamic(input_statements/1).\n:- dynamic(intern/1).\n:- dynamic(keep_skolem/1).\n:- dynamic(lemma/6). % lemma(Count, Source, Premise, Conclusion, Premise-Conclusion_index, Rule)\n:- dynamic(model/3).\n:- dynamic(modelo/3).\n:- dynamic(mtime/2).\n:- dynamic(n3s/2).\n:- dynamic(ncllit/0).\n:- dynamic(ns/2).\n:- dynamic(pass_only_new/1).\n:- dynamic(pfx/2).\n:- dynamic(pred/1).\n:- dynamic(prfstep/7). % prfstep(Conclusion_triple, Premise, Premise_index, Conclusion, Rule, Chaining, Source)\n:- dynamic(qevar/3).\n:- dynamic(query/2).\n:- dynamic(quvar/3).\n:- dynamic(retwist/3).\n:- dynamic(rule_uvar/1).\n:- dynamic(scope/1).\n:- dynamic(scount/1).\n:- dynamic(semantics/2).\n:- dynamic(span/1).\n:- dynamic(tabl/3).\n:- dynamic(tmpfile/1).\n:- dynamic(tuple/2).\n:- dynamic(tuple/3).\n:- dynamic(tuple/4).\n:- dynamic(tuple/5).\n:- dynamic(tuple/6).\n:- dynamic(tuple/7).\n:- dynamic(tuple/8).\n:- dynamic(wcache/2).\n:- dynamic(wpfx/1).\n:- dynamic(wtcache/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#biconditional>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#call>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#conditional>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tactic>'/2).\n:- dynamic('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'/2).\n:- dynamic('<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>'/2).\n:- dynamic('<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'/2).\n:- dynamic('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'/2).\n:- dynamic('<http://www.w3.org/2000/01/rdf-schema#subClassOf>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#callWithCleanup>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#implies>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#onNeutralSurface>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/log#outputString>'/2).\n:- dynamic('<http://www.w3.org/2000/10/swap/reason#source>'/2).\n\n%\n% Main goal\n%\n\nmain(Argv) :-\n set_prolog_flag(argv, Argv),\n catch(run, Exc,\n ( Exc = halt(_)\n -> true\n ; throw(Exc)\n )\n ).\n\nmain :-\n catch(run, Exc,\n ( Exc = halt(EC)\n -> halt(EC)\n ; throw(Exc)\n )\n ).\n\nrun :-\n current_prolog_flag(version_data, swi(SV, _, _, _)),\n ( SV < 8\n -> format(user_error, '** ERROR ** EYE requires at least swipl version 8 **~n', []),\n flush_output(user_error),\n throw(halt(1))\n ; true\n ),\n catch(set_stream(user_output, encoding(utf8)), _, true),\n current_prolog_flag(argv, Argv),\n ( append(_, ['--'|Argvp], Argv)\n -> true\n ; Argvp = Argv\n ),\n ( Argvp = ['--source', File]\n -> ( File = '-'\n -> read_line_to_codes(user_input, Codes)\n ; read_file_to_codes(File, Codes, [])\n ),\n atom_codes(Atom, Codes),\n atomic_list_concat(Argvs, ' ', Atom)\n ; Argvs = Argvp\n ),\n argv(Argvs, Argus),\n findall(Argij,\n ( argi(Argij)\n ),\n Argil\n ),\n append(Argil, Argi),\n ( member('--quiet', Argus)\n -> true\n ; format(user_error, 'eye~@~@~n', [w0(Argi), w1(Argus)]),\n version_info(Version),\n format(user_error, '~w~n', [Version]),\n ( current_prolog_flag(version_git, PVersion)\n -> true\n ; current_prolog_flag(version_data, swi(Major, Minor, Patch, Options)),\n ( memberchk(tag(Tag), Options)\n -> atomic_list_concat([Major, '.', Minor, '.', Patch, '-', Tag], PVersion)\n ; atomic_list_concat([Major, '.', Minor, '.', Patch], PVersion)\n )\n ),\n format(user_error, 'SWI-Prolog version ~w~n', [PVersion]),\n flush_output(user_error)\n ),\n ( retract(prolog_file_type(qlf, qlf))\n -> assertz(prolog_file_type(pvm, qlf))\n ; true\n ),\n ( Argv = ['--n3', _]\n -> retractall(flag('parse-only')),\n assertz(flag('parse-only'))\n ; true\n ),\n catch(gre(Argus), Exc,\n ( Exc = halt(0)\n -> true\n ; ( flag('parse-only')\n -> true\n ; format(user_error, '** ERROR ** gre ** ~w~n', [Exc]),\n flush_output(user_error),\n nb_setval(exit_code, 3)\n )\n )\n ),\n ( flag(statistics)\n -> statistics\n ; true\n ),\n ( flag('debug-implies')\n -> mf(implies(_, _, _))\n ; true\n ),\n ( flag('debug-pvm')\n -> tell(user_error),\n ignore(vm_list(_)),\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n )\n ; true\n ),\n ( flag('debug-djiti')\n -> tell(user_error),\n jiti_list,\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n )\n ; true\n ),\n nb_getval(exit_code, EC),\n flush_output,\n throw(halt(EC)).\n\nargv([], []) :-\n !.\nargv([Arg|Argvs], [U, V|Argus]) :-\n sub_atom(Arg, B, 1, E, '='),\n sub_atom(Arg, 0, B, _, U),\n memberchk(U, ['--csv-separator', '--hmac-key', '--image', '--max-inferences', '--n3', '--n3p', '--proof', '--quantify', '--query', '--output', '--skolem-genid', '--tactic', '--turtle']),\n !,\n sub_atom(Arg, _, E, 0, V),\n argv(Argvs, Argus).\nargv([Arg|Argvs], [Arg|Argus]) :-\n argv(Argvs, Argus).\n\n\n% ------------------------------\n% GRE (Generic Reasoning Engine)\n% ------------------------------\n\ngre(Argus) :-\n statistics(runtime, [T0, _]),\n statistics(walltime, [T1, _]),\n ( member('--quiet', Argus)\n -> true\n ; format(user_error, 'starting ~w [msec cputime] ~w [msec walltime]~n', [T0, T1]),\n flush_output(user_error)\n ),\n nb_setval(entail_mode, false),\n nb_setval(exit_code, 0),\n nb_setval(indentation, 0),\n nb_setval(limit, -1),\n nb_setval(bnet, not_done),\n nb_setval(fnet, not_done),\n nb_setval(tabl, -1),\n nb_setval(tuple, -1),\n nb_setval(fdepth, 0),\n nb_setval(pdepth, 0),\n nb_setval(cdepth, 0),\n nb_setval(mconc, false),\n ( input_statements(Ist)\n -> nb_setval(input_statements, Ist)\n ; nb_setval(input_statements, 0)\n ),\n nb_setval(output_statements, 0),\n nb_setval(current_scope, '<>'),\n nb_setval(wn, 0),\n opts(Argus, Args),\n ( \\+flag('multi-query'),\n Args = []\n -> opts(['--help'], _)\n ; true\n ),\n ( flag('skolem-genid', Genid)\n -> true\n ; A is random(2^62),\n atom_number(Genid, A)\n ),\n atomic_list_concat(['http://eyereasoner.github.io/.well-known/genid/', Genid, '#'], Sns),\n nb_setval(var_ns, Sns),\n ( ( flag(strings)\n ; flag(image, _)\n )\n -> true\n ; version_info(Version),\n ( flag(quiet)\n -> true\n ; format('#Processed by ~w~n', [Version])\n ),\n findall(Argij,\n ( argi(Argij)\n ),\n Argil\n ),\n append(Argil, Argi),\n ( flag(quiet)\n -> true\n ; format('#eye~@~@~n~n', [w0(Argi), w1(Argus)]),\n flush_output\n )\n ),\n ( ( flag('no-qvars')\n ; flag('pass-all-ground')\n )\n -> retractall(pfx('var:', _)),\n assertz(pfx('var:', '<http://eyereasoner.github.io/var#>'))\n ; true\n ),\n ( flag(intermediate, Out)\n -> format(Out, 'flag(\\'quantify\\', \\'~w\\').~n', [Sns])\n ; true\n ),\n args(Args),\n ( implies(_, Conc, _),\n ( var(Conc)\n ; Conc \\= answer(_, _, _),\n Conc \\= (answer(_, _, _), _)\n )\n -> true\n ; ( \\+flag(image, _),\n \\+flag(tactic, 'linear-select')\n -> assertz(flag(tactic, 'linear-select'))\n ; true\n )\n ),\n findall(Sc,\n ( scope(Sc)\n ),\n Scope\n ),\n nb_setval(scope, Scope),\n statistics(runtime, [_, T2]),\n statistics(walltime, [_, T3]),\n ( flag(quiet)\n -> true\n ; format(user_error, 'networking ~w [msec cputime] ~w [msec walltime]~n', [T2, T3]),\n flush_output(user_error)\n ),\n nb_getval(input_statements, SC),\n ( flag(image, File)\n -> assertz(argi(Argus)),\n retractall(flag(image, _)),\n assertz(flag('quantify', Sns)),\n retractall(input_statements(_)),\n assertz(input_statements(SC)),\n reset_gensym,\n ( current_predicate(qsave:qsave_program/1)\n -> qsave_program(File)\n ; save_program(File)\n ),\n throw(halt(0))\n ; true\n ),\n ( flag(intermediate, Out)\n -> ( SC =\\= 0\n -> write(Out, scount(SC)),\n writeln(Out, '.')\n ; true\n ),\n writeln(Out, 'end_of_file.'),\n close(Out)\n ; true\n ),\n ( \\+implies(_, answer(_, _, _), _),\n \\+implies(_, (answer(_, _, _), _), _),\n \\+query(_, _),\n \\+flag('pass-only-new'),\n \\+flag('multi-query'),\n \\+flag(strings)\n -> throw(halt(0))\n ; true\n ),\n ( flag(nope)\n -> true\n ; ( pfx('r:', _)\n -> true\n ; assertz(pfx('r:', '<http://www.w3.org/2000/10/swap/reason#>'))\n ),\n ( pfx('var:', _)\n -> true\n ; assertz(pfx('var:', '<http://eyereasoner.github.io/var#>'))\n ),\n ( pfx('skolem:', _)\n -> true\n ; nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, '>'], B),\n assertz(pfx('skolem:', B))\n ),\n ( pfx('n3:', _)\n -> true\n ; assertz(pfx('n3:', '<http://www.w3.org/2004/06/rei#>'))\n )\n ),\n nb_setval(tr, 0),\n nb_setval(tc, 0),\n nb_setval(tp, 0),\n nb_setval(rn, 0),\n nb_setval(lemma_count, 0),\n nb_setval(lemma_cursor, 0),\n nb_setval(answer_count, 0),\n ( flag('multi-query')\n -> nb_setval(mq, 0),\n repeat,\n catch((read_line_to_codes(user_input, Fc), atom_codes(Fa, Fc)), _, Fa = end_of_file),\n ( atomic_list_concat([Fi, Fo], ', ', Fa)\n -> open(Fo, write, Fos, [encoding(utf8)])\n ; Fi = Fa,\n ( flag('output', Output)\n -> Fos = Output\n ; Fos = user_output\n )\n ),\n tell(Fos),\n ( Fi = end_of_file\n -> true\n ; statistics(walltime, [_, _]),\n nb_getval(output_statements, Outb),\n statistics(inferences, Infb),\n ( flag(blogic)\n -> Amq = ['--n3', Fi]\n ; Amq = ['--query', Fi]\n ),\n catch(args(Amq), Exc1,\n ( format(user_error, '** ERROR ** args ** ~w~n', [Exc1]),\n flush_output(user_error),\n nb_setval(exit_code, 3)\n )\n ),\n catch(eam(0), Exc2,\n ( ( Exc2 = halt(0)\n -> true\n ; format(user_error, '** ERROR ** eam ** ~w~n', [Exc2]),\n flush_output(user_error),\n ( Exc2 = inference_fuse(_)\n -> nb_setval(exit_code, 2)\n ; nb_setval(exit_code, 3)\n )\n )\n )\n ),\n ( flag(strings)\n -> wst\n ; true\n ),\n forall(\n ( answer(A1, A2, A3),\n nonvar(A1)\n ),\n retract(answer(A1, A2, A3))\n ),\n retractall(implies(_, answer(_, _, _), _)),\n retractall(implies(_, (answer(_, _, _), _), _)),\n retractall(query(_, _)),\n retractall('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(_, _)),\n retractall(cc(_)),\n retractall(brake),\n retractall(prfstep(answer(_, _, _), _, _, _, _, _, _)),\n retractall(lemma(_, _, _, _, _, _)),\n retractall(got_wi(_, _, _, _, _)),\n retractall(wpfx(_)),\n retractall('<http://www.w3.org/2000/10/swap/log#outputString>'(_, _)),\n retractall('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>'(_, _)),\n nb_setval(csv_header, []),\n cnt(mq),\n nb_getval(mq, Cnt),\n ( Cnt mod 10000 =:= 0\n -> garbage_collect_atoms\n ; true\n ),\n statistics(runtime, [_, Ti4]),\n statistics(walltime, [_, Ti5]),\n ( flag(quiet)\n -> true\n ; format(user_error, 'reasoning ~w [msec cputime] ~w [msec walltime]~n', [Ti4, Ti5]),\n flush_output(user_error)\n ),\n nb_getval(output_statements, Oute),\n Outd is Oute-Outb,\n catch(Outs is round(Outd/Ti5*1000), _, Outs = ''),\n ( ( flag(strings)\n ; flag(quiet)\n )\n -> nl\n ; format('#DONE ~3d [sec] mq=~w out=~d out/sec=~w~n~n', [Ti5, Cnt, Outd, Outs])\n ),\n timestamp(Stmp),\n statistics(inferences, Infe),\n Infd is Infe-Infb,\n catch(Infs is round(Infd/Ti5*1000), _, Infs = ''),\n ( flag(quiet)\n -> true\n ; format(user_error, '~w mq=~w out=~d inf=~w sec=~3d out/sec=~w inf/sec=~w~n~n', [Stmp, Cnt, Outd, Infd, Ti5, Outs, Infs]),\n flush_output(user_error)\n ),\n fail\n ),\n told\n ; ( flag(profile)\n -> asserta(pce_profile:pce_show_profile :- fail),\n profiler(_, cputime)\n ; true\n ),\n catch(eam(0), Exc3,\n ( ( Exc3 = halt(0)\n -> true\n ; format(user_error, '** ERROR ** eam ** ~w~n', [Exc3]),\n flush_output(user_error),\n ( Exc3 = inference_fuse(_)\n -> nb_setval(exit_code, 2)\n ; nb_setval(exit_code, 3)\n )\n )\n )\n ),\n ( flag('pass-only-new')\n -> wh,\n forall(\n pass_only_new(Zn),\n ( indent,\n relabel(Zn, Zr),\n wt(Zr),\n ws(Zr),\n write('.'),\n nl,\n cnt(output_statements)\n )\n ),\n nl\n ; true\n ),\n ( flag(profile)\n -> profiler(_, false),\n tell(user_error),\n show_profile([]),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n )\n ; true\n )\n ),\n ( flag(strings)\n -> wst\n ; true\n ),\n nb_getval(tc, TC),\n nb_getval(tp, TP),\n statistics(runtime, [_, T4]),\n statistics(walltime, [_, T5]),\n ( \\+flag('multi-query')\n -> ( flag(quiet)\n -> true\n ; format(user_error, 'reasoning ~w [msec cputime] ~w [msec walltime]~n', [T4, T5]),\n flush_output(user_error)\n )\n ; true\n ),\n nb_getval(input_statements, Inp),\n nb_getval(output_statements, Outp),\n timestamp(Stamp),\n Ent is TC,\n Step is TP,\n statistics(runtime, [Cpu, _]),\n nb_getval(tr, TR),\n Brake is TR,\n ( statistics(inferences, Inf)\n -> true\n ; Inf = ''\n ),\n catch(Speed is round(Inf/Cpu*1000), _, Speed = ''),\n ( ( flag(strings)\n ; flag(quiet)\n )\n -> true\n ; format('#~w in=~d out=~d ent=~d step=~w brake=~w inf=~w sec=~3d inf/sec=~w~n#ENDS~n~n', [Stamp, Inp, Outp, Ent, Step, Brake, Inf, Cpu, Speed])\n ),\n ( flag(quiet)\n -> true\n ; format(user_error, '~w in=~d out=~d ent=~d step=~w brake=~w inf=~w sec=~3d inf/sec=~w~n~n', [Stamp, Inp, Outp, Ent, Step, Brake, Inf, Cpu, Speed]),\n flush_output(user_error)\n ),\n ( flag('rule-histogram')\n -> findall([RTC, RTP, R],\n ( tabl(ETP, tp, Rule),\n nb_getval(ETP, RTP),\n ( tabl(ETC, tc, Rule)\n -> nb_getval(ETC, RTC)\n ; RTC = 0\n ),\n with_output_to(atom(R), wt(Rule))\n ),\n CntRl\n ),\n sort(CntRl, CntRs),\n reverse(CntRs, CntRr),\n format(user_error, '>>> rule histogram TR=~w <<<~n', [TR]),\n forall(\n member(RCnt, CntRr),\n ( ( last(RCnt, '<http://www.w3.org/2000/10/swap/log#implies>'(X, Y)),\n conj_append(X, pstep(_), Z),\n catch(clause(Y, Z), _, fail)\n -> format(user_error, 'TC=~w TP=~w for component ~w~n', RCnt)\n ; format(user_error, 'TC=~w TP=~w for rule ~w~n', RCnt)\n )\n )\n ),\n format(user_error, '~n', []),\n flush_output(user_error)\n ; true\n ).\n\n%\n% command line options\n%\n\nopts([], []) :-\n !.\nopts(['--blogic'|Argus], Args) :-\n !,\n retractall(flag(blogic)),\n assertz(flag(blogic)),\n retractall(flag(nope)),\n assertz(flag(nope)),\n assertz(implies((implies(D, C, _),\n conj_list(D, K),\n conj_list(C, L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, _), L),\n \\+member(answer(_, _, _), L),\n model(Z, R, J),\n findall(M,\n ( member(M, K),\n ( member(M, J)\n ; M =.. [U, _, _],\n pred(U),\n call(M)\n )\n ),\n Q\n ),\n unify(K, Q),\n ( L = [model(_, [case(P, A)], B)]\n -> \\+member(case(P, _), R),\n append(R, [case(P, A)], T),\n append(J, B, I)\n ; T = R,\n append(J, L, I)\n ),\n sort(I, H),\n H \\= J\n ), (modelo(Z, R, J), model(Z, T, H)), '<>')),\n assertz(implies((implies(D, C, _),\n implies('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, D), C, _),\n labelvars(C, 0, _, some),\n findvars(C, V, beta),\n domain(V, true, P),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'(P, C), B, beta(V))\n ), B, '<>')),\n assertz(implies('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(_, G), G, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n makevars(G, H, beta(V)),\n call(H)\n ), false, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, H), L, K),\n conj_list(C, K),\n conj_list(H, M),\n select('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, C), M, _)\n ), '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, C), '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, H), L, K),\n conj_list(C, K),\n domain(V, C, P),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'(P, H), B, beta(V))\n ), B, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, H), L, K),\n dsplit(K, M, J),\n J \\= [],\n conj_list(R, M),\n conj_list(T, J),\n ( H = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, A)\n -> D = A\n ; D = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, H)\n ),\n ( T = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, F)\n -> E = F\n ; E = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, T)\n ),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'((D, R), E), B, beta(V))\n ), B, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(W, H), L, K),\n conj_list(R, K),\n ( H = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, A)\n -> D = A\n ; D = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(W, H)\n ),\n domain(V, R, P),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'(P, D), B, beta(V))\n ), B, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, _), L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(_, _), L),\n select('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'([], H), L, K),\n conj_list(H, D),\n append(K, D, E),\n conj_list(F, E)\n ), '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, F), '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(_, _), L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, _), L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(_, _), L),\n \\+member('<http://www.w3.org/2000/10/swap/log#onConstructSurface>'(_, _), L),\n dsplit(L, M, J),\n J \\= [],\n conj_list(R, M),\n conj_list(T, J),\n E = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'([], T),\n domain(V, R, P),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'(P, E), B, beta(V))\n ), B, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, H), L, K),\n findall(M,\n ( member(M, K),\n M \\= '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, _)\n ),\n J\n ),\n conj_list(C, J),\n length(K, N),\n length(J, I),\n N > I,\n conj_list(H, Q),\n sort(Q, A),\n domain(V, C, P),\n makevars('<http://www.w3.org/2000/10/swap/log#implies>'(P, model(domain(P), [case(C, H)], A)), B, beta(V))\n ), B, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(V, G),\n conj_list(G, L),\n select('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(_, H), L, K),\n conj_list(R, K),\n makevars(':-'(H, R), C, beta(V)),\n copy_term_nat(C, CC),\n labelvars(CC, 0, _, avar),\n ( \\+cc(CC)\n -> assertz(cc(CC)),\n assertz(C)\n ; true\n )), true, '<>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(V, G),\n conj_list(G, L),\n ( select('<http://www.w3.org/2000/10/swap/log#onConstructSurface>'(_, H), L, K)\n -> conj_list(I, K)\n ; I = G,\n H = G\n ),\n djiti_answer(answer(H), J),\n makevars(implies(I, J, '<>'), C, beta(V)),\n copy_term_nat(C, CC),\n labelvars(CC, 0, _, avar),\n ( \\+cc(CC)\n -> assertz(cc(CC)),\n assertz(C),\n retractall(brake)\n ; true\n )), true, '<>')),\n opts(Argus, Args).\nopts(['--csv-separator',Separator|Argus], Args) :-\n !,\n retractall(flag('csv-separator')),\n assertz(flag('csv-separator', Separator)),\n opts(Argus, Args).\nopts(['--debug'|Argus], Args) :-\n !,\n retractall(flag(debug)),\n assertz(flag(debug)),\n opts(Argus, Args).\nopts(['--debug-cnt'|Argus], Args) :-\n !,\n retractall(flag('debug-cnt')),\n assertz(flag('debug-cnt')),\n opts(Argus, Args).\nopts(['--debug-djiti'|Argus], Args) :-\n !,\n retractall(flag('debug-djiti')),\n assertz(flag('debug-djiti')),\n opts(Argus, Args).\nopts(['--debug-implies'|Argus], Args) :-\n !,\n retractall(flag('debug-implies')),\n assertz(flag('debug-implies')),\n opts(Argus, Args).\nopts(['--debug-models'|Argus], Args) :-\n !,\n retractall(flag('debug-models')),\n assertz(flag('debug-models')),\n opts(Argus, Args).\nopts(['--debug-pvm'|Argus], Args) :-\n !,\n retractall(flag('debug-pvm')),\n assertz(flag('debug-pvm')),\n opts(Argus, Args).\nopts(['--help'|_], _) :-\n \\+flag(image, _),\n \\+flag('debug-pvm'),\n !,\n help_info(Help),\n format(user_error, '~w~n', [Help]),\n flush_output(user_error),\n throw(halt(0)).\nopts(['--hmac-key',Key|Argus], Args) :-\n !,\n retractall(flag('hmac-key', _)),\n assertz(flag('hmac-key', Key)),\n opts(Argus, Args).\nopts(['--ignore-inference-fuse'|Argus], Args) :-\n !,\n retractall(flag('ignore-inference-fuse')),\n assertz(flag('ignore-inference-fuse')),\n opts(Argus, Args).\nopts(['--image',File|Argus], Args) :-\n !,\n retractall(flag(image, _)),\n assertz(flag(image, File)),\n opts(Argus, Args).\nopts(['--license'|_], _) :-\n !,\n license_info(License),\n format(user_error, '~w~n', [License]),\n flush_output(user_error),\n throw(halt(0)).\nopts(['--max-inferences',Lim|Argus], Args) :-\n !,\n ( number(Lim)\n -> Limit = Lim\n ; catch(atom_number(Lim, Limit), Exc,\n ( format(user_error, '** ERROR ** max-inferences ** ~w~n', [Exc]),\n flush_output(user_error),\n flush_output,\n throw(halt(1))\n )\n )\n ),\n retractall(flag('max-inferences', _)),\n assertz(flag('max-inferences', Limit)),\n opts(Argus, Args).\nopts(['--multi-query'|Argus], Args) :-\n !,\n retractall(flag('multi-query')),\n assertz(flag('multi-query')),\n opts(Argus, Args).\nopts(['--no-distinct-input'|Argus], Args) :-\n !,\n retractall(flag('no-distinct-input')),\n assertz(flag('no-distinct-input')),\n opts(Argus, Args).\nopts(['--no-distinct-output'|Argus], Args) :-\n !,\n retractall(flag('no-distinct-output')),\n assertz(flag('no-distinct-output')),\n opts(Argus, Args).\nopts(['--no-erase'|Argus], Args) :-\n !,\n retractall(flag('no-erase')),\n assertz(flag('no-erase')),\n opts(Argus, Args).\nopts(['--no-numerals'|Argus], Args) :-\n !,\n retractall(flag('no-numerals')),\n assertz(flag('no-numerals')),\n opts(Argus, Args).\nopts(['--no-qnames'|Argus], Args) :-\n !,\n retractall(flag('no-qnames')),\n assertz(flag('no-qnames')),\n opts(Argus, Args).\nopts(['--no-qvars'|Argus], Args) :-\n !,\n retractall(flag('no-qvars')),\n assertz(flag('no-qvars')),\n opts(Argus, Args).\nopts(['--no-ucall'|Argus], Args) :-\n !,\n retractall(flag('no-ucall')),\n assertz(flag('no-ucall')),\n opts(Argus, Args).\nopts(['--nope'|Argus], Args) :-\n !,\n retractall(flag(nope)),\n assertz(flag(nope)),\n opts(Argus, Args).\nopts(['--output',File|Argus], Args) :-\n !,\n retractall(flag('output', _)),\n open(File, write, Out, [encoding(utf8)]),\n tell(Out),\n assertz(flag('output', Out)),\n opts(Argus, Args).\nopts(['--pass-all-ground'|Argus], Args) :-\n !,\n retractall(flag('pass-all-ground')),\n assertz(flag('pass-all-ground')),\n opts(['--pass-all'|Argus], Args).\nopts(['--pass-only-new'|Argus], Args) :-\n !,\n retractall(flag('pass-only-new')),\n assertz(flag('pass-only-new')),\n opts(Argus, Args).\nopts(['--intermediate',File|Argus], Args) :-\n !,\n retractall(flag(intermediate, _)),\n open(File, write, Out, [encoding(utf8)]),\n assertz(flag(intermediate, Out)),\n opts(Argus, Args).\nopts(['--profile'|Argus], Args) :-\n !,\n retractall(flag(profile)),\n assertz(flag(profile)),\n opts(Argus, Args).\nopts(['--quantify',Prefix|Argus], Args) :-\n !,\n assertz(flag('quantify', Prefix)),\n opts(Argus, Args).\nopts(['--quiet'|Argus], Args) :-\n !,\n retractall(flag(quiet)),\n assertz(flag(quiet)),\n opts(Argus, Args).\nopts(['--random-seed'|Argus], Args) :-\n !,\n N is random(2^120),\n nb_setval(random, N),\n opts(Argus, Args).\nopts(['--restricted'|Argus], Args) :-\n !,\n retractall(flag(restricted)),\n assertz(flag(restricted)),\n opts(Argus, Args).\nopts(['--rule-histogram'|Argus], Args) :-\n !,\n retractall(flag('rule-histogram')),\n assertz(flag('rule-histogram')),\n opts(Argus, Args).\nopts(['--skolem-genid',Genid|Argus], Args) :-\n !,\n retractall(flag('skolem-genid', _)),\n assertz(flag('skolem-genid', Genid)),\n opts(Argus, Args).\nopts(['--statistics'|Argus], Args) :-\n !,\n retractall(flag(statistics)),\n assertz(flag(statistics)),\n opts(Argus, Args).\nopts(['--strings'|Argus], Args) :-\n !,\n retractall(flag(strings)),\n assertz(flag(strings)),\n opts(Argus, Args).\nopts(['--tactic','limited-answer',Lim|Argus], Args) :-\n !,\n ( number(Lim)\n -> Limit = Lim\n ; catch(atom_number(Lim, Limit), Exc,\n ( format(user_error, '** ERROR ** limited-answer ** ~w~n', [Exc]),\n flush_output(user_error),\n flush_output,\n throw(halt(1))\n )\n )\n ),\n retractall(flag('limited-answer', _)),\n assertz(flag('limited-answer', Limit)),\n opts(Argus, Args).\nopts(['--tactic','linear-select'|Argus], Args) :-\n !,\n retractall(flag(tactic, 'linear-select')),\n assertz(flag(tactic, 'linear-select')),\n opts(Argus, Args).\nopts(['--tactic',Tactic|_], _) :-\n !,\n throw(not_supported_tactic(Tactic)).\nopts(['--version'|_], _) :-\n !,\n throw(halt(0)).\nopts(['--warn'|Argus], Args) :-\n !,\n retractall(flag(warn)),\n assertz(flag(warn)),\n opts(Argus, Args).\nopts(['--wcache',Argument,File|Argus], Args) :-\n !,\n absolute_uri(Argument, Arg),\n retractall(wcache(Arg, _)),\n assertz(wcache(Arg, File)),\n opts(Argus, Args).\nopts([Arg|_], _) :-\n \\+memberchk(Arg, ['--entail', '--help', '--n3', '--n3p', '--not-entail', '--pass', '--pass-all', '--proof', '--query', '--turtle']),\n sub_atom(Arg, 0, 2, _, '--'),\n !,\n throw(not_supported_option(Arg)).\nopts([Arg|Argus], [Arg|Args]) :-\n opts(Argus, Args).\n\nargs([]) :-\n !.\nargs(['--entail',Arg|Args]) :-\n !,\n nb_setval(entail_mode, true),\n n3_n3p(Arg, entail),\n nb_setval(entail_mode, false),\n args(Args).\nargs(['--not-entail',Arg|Args]) :-\n !,\n nb_setval(entail_mode, true),\n n3_n3p(Arg, 'not-entail'),\n nb_setval(entail_mode, false),\n args(Args).\nargs(['--n3',Arg|Args]) :-\n !,\n absolute_uri(Arg, A),\n atomic_list_concat(['<', A, '>'], R),\n assertz(scope(R)),\n ( flag(intermediate, Out)\n -> portray_clause(Out, scope(R))\n ; true\n ),\n n3_n3p(Arg, data),\n nb_setval(fdepth, 0),\n nb_setval(pdepth, 0),\n nb_setval(cdepth, 0),\n args(Args).\nargs(['--n3p',Argument|Args]) :-\n !,\n retractall(flag(n3p)),\n assertz(flag(n3p)),\n absolute_uri(Argument, Arg),\n ( wcacher(Arg, File)\n -> ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w FROM ~w ', [Arg, File]),\n flush_output(user_error)\n ),\n open(File, read, In, [encoding(utf8)])\n ; ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w ', [Arg]),\n flush_output(user_error)\n ),\n ( ( sub_atom(Arg, 0, 5, _, 'http:')\n -> true\n ; sub_atom(Arg, 0, 6, _, 'https:')\n )\n -> http_open(Arg, In, []),\n set_stream(In, encoding(utf8))\n ; ( sub_atom(Arg, 0, 5, _, 'file:')\n -> ( parse_url(Arg, Parts)\n -> memberchk(path(File), Parts)\n ; sub_atom(Arg, 7, _, 0, File)\n )\n ; File = Arg\n ),\n ( File = '-'\n -> In = user_input\n ; open(File, read, In, [encoding(utf8)])\n )\n )\n ),\n repeat,\n read_term(In, Rt, []),\n ( Rt = end_of_file\n -> catch(read_term(In, _, []), _, true)\n ; n3pin(Rt, In, File, data),\n fail\n ),\n !,\n ( File = '-'\n -> true\n ; close(In)\n ),\n ( retract(tmpfile(File))\n -> delete_file(File)\n ; true\n ),\n findall(SCnt,\n ( retract(scount(SCnt))\n ),\n SCnts\n ),\n sum(SCnts, SC),\n nb_getval(input_statements, IN),\n Inp is SC+IN,\n nb_setval(input_statements, Inp),\n ( flag(quiet)\n -> true\n ; ( SC =\\= 0\n -> format(user_error, 'SC=~w~n', [SC])\n ; format(user_error, '~n', [])\n ),\n flush_output(user_error)\n ),\n args(Args).\nargs(['--pass'|Args]) :-\n !,\n ( flag(nope),\n \\+flag('limited-answer', _),\n ( flag('no-distinct-input')\n -> flag('no-distinct-output')\n ; true\n ),\n \\+implies(_, answer(_, _, _), _),\n \\+implies(_, (answer(_, _, _), _), _)\n -> assertz(query(exopred(P, S, O), exopred(P, S, O)))\n ; assertz(implies(exopred(P, S, O), answer(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/pass>'))\n ),\n ( flag(intermediate, Out)\n -> portray_clause(Out, implies(exopred(P, S, O), answer(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/pass>'))\n ; true\n ),\n args(Args).\nargs(['--pass-all'|Args]) :-\n !,\n assertz(implies((exopred(P, S, O), \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(P, '<http://www.w3.org/2000/10/swap/log#implies>')),\n answer(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>')),\n assertz(implies(('<http://www.w3.org/2000/10/swap/log#implies>'(A, C), \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(A, true)),\n answer('<http://www.w3.org/2000/10/swap/log#implies>', A, C), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>')),\n assertz(implies(':-'(C, A),\n answer(':-', C, A), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>')),\n ( flag(intermediate, Out)\n -> portray_clause(Out, implies((exopred(P, S, O), \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(P, '<http://www.w3.org/2000/10/swap/log#implies>')),\n answer(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>')),\n portray_clause(Out, implies(('<http://www.w3.org/2000/10/swap/log#implies>'(A, C), \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(A, true)),\n answer('<http://www.w3.org/2000/10/swap/log#implies>', A, C), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>')),\n portray_clause(Out, implies((':-'(C, A), \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(A, true)),\n answer(':-', C, A), '<http://eulersharp.sourceforge.net/2003/03swap/pass-all>'))\n ; true\n ),\n args(Args).\nargs(['--proof',Arg|Args]) :-\n !,\n absolute_uri(Arg, A),\n atomic_list_concat(['<', A, '>'], R),\n assertz(scope(R)),\n ( flag(intermediate, Out)\n -> portray_clause(Out, scope(R))\n ; true\n ),\n n3_n3p(Arg, data),\n ( got_pi\n -> true\n ; assertz(implies(('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'(LEMMA, '<http://www.w3.org/2000/10/swap/reason#Inference>'),\n '<http://www.w3.org/2000/10/swap/reason#gives>'(LEMMA, GRAPH),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphMember>'(GRAPH, exopred(P, S, O))),\n exopred(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/proof-lemma>')),\n assertz(implies(('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'(LEMMA, '<http://www.w3.org/2000/10/swap/reason#Extraction>'),\n '<http://www.w3.org/2000/10/swap/reason#gives>'(LEMMA, GRAPH),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphMember>'(GRAPH, exopred(P, S, O))),\n exopred(P, S, O), '<http://eulersharp.sourceforge.net/2003/03swap/proof-lemma>')),\n assertz(got_pi)\n ),\n args(Args).\nargs(['--query',Arg|Args]) :-\n !,\n n3_n3p(Arg, query),\n args(Args).\nargs(['--turtle',Argument|Args]) :-\n !,\n absolute_uri(Argument, Arg),\n atomic_list_concat(['<', Arg, '>'], R),\n assertz(scope(R)),\n ( flag(intermediate, Out)\n -> portray_clause(Out, scope(R))\n ; true\n ),\n ( wcacher(Arg, File)\n -> ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w FROM ~w ', [Arg, File]),\n flush_output(user_error)\n ),\n open(File, read, In, [encoding(utf8)])\n ; ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w ', [Arg]),\n flush_output(user_error)\n ),\n ( ( sub_atom(Arg, 0, 5, _, 'http:')\n -> true\n ; sub_atom(Arg, 0, 6, _, 'https:')\n )\n -> http_open(Arg, In, []),\n set_stream(In, encoding(utf8))\n ; ( sub_atom(Arg, 0, 5, _, 'file:')\n -> ( parse_url(Arg, Parts)\n -> memberchk(path(File), Parts)\n ; sub_atom(Arg, 7, _, 0, File)\n )\n ; File = Arg\n ),\n ( File = '-'\n -> In = user_input\n ; open(File, read, In, [encoding(utf8)])\n )\n )\n ),\n retractall(base_uri(_)),\n ( Arg = '-'\n -> absolute_uri('', Abu),\n assertz(base_uri(Abu))\n ; assertz(base_uri(Arg))\n ),\n retractall(ns(_, _)),\n ( Arg = '-'\n -> D = '#'\n ; atomic_list_concat([Arg, '#'], D)\n ),\n assertz(ns('', D)),\n nb_setval(sc, 0),\n rdf_read_turtle(stream(In), Triples, []),\n close(In),\n forall(\n member(rdf(S, P, O), Triples),\n ( ttl_n3p(S, Subject),\n ttl_n3p(P, Predicate),\n ttl_n3p(O, Object),\n Triple =.. [Predicate, Subject, Object],\n djiti_assertz(Triple),\n ( flag(intermediate, Out)\n -> format(Out, '~q.~n', [Triple])\n ; true\n ),\n ( flag(nope)\n -> true\n ; assertz(prfstep(Triple, true, _, Triple, _, forward, R))\n )\n )\n ),\n length(Triples, SC),\n nb_getval(input_statements, IN),\n Inp is SC+IN,\n nb_setval(input_statements, Inp),\n ( flag(quiet)\n -> true\n ; format(user_error, 'SC=~w~n', [SC]),\n flush_output(user_error)\n ),\n args(Args).\nargs([Arg|Args]) :-\n args(['--n3', Arg|Args]).\n\nn3pin(Rt, In, File, Mode) :-\n ( Rt = ':-'(Rg)\n -> ( flag('parse-only')\n -> true\n ; call(Rg)\n ),\n ( flag(intermediate, Out)\n -> format(Out, '~q.~n', [Rt])\n ; true\n )\n ; dynify(Rt),\n ( ( Rt = ':-'(Rh, _)\n -> predicate_property(Rh, dynamic)\n ; predicate_property(Rt, dynamic)\n )\n -> true\n ; ( File = '-'\n -> true\n ; close(In)\n ),\n ( retract(tmpfile(File))\n -> delete_file(File)\n ; true\n ),\n throw(builtin_redefinition(Rt))\n ),\n ( Rt = pfx(Pfx, _)\n -> retractall(pfx(Pfx, _))\n ; true\n ),\n ( Rt = scope(Scope)\n -> nb_setval(current_scope, Scope)\n ; true\n ),\n ( Rt = ':-'(Ci, Px),\n conjify(Px, Pi)\n -> ( Ci = true\n -> ( flag('parse-only')\n -> true\n ; call(Pi)\n )\n ; nb_getval(current_scope, Si),\n copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(Pi, Ci), Ri),\n ( flag(nope)\n -> Ph = Pi\n ; ( Pi = when(Ai, Bi)\n -> conj_append(Bi, istep(Si, Pi, Ci, Ri), Bh),\n Ph = when(Ai, Bh)\n ; conj_append(Pi, istep(Si, Pi, Ci, Ri), Ph)\n )\n ),\n ( flag('rule-histogram')\n -> ( Ph = when(Ak, Bk)\n -> conj_append(Bk, pstep(Ri), Bj),\n Pj = when(Ak, Bj)\n ; conj_append(Ph, pstep(Ri), Pj)\n )\n ; Pj = Ph\n ),\n functor(Ci, CPi, _),\n ( flag(intermediate, Out)\n -> ( \\+cpred(CPi)\n -> portray_clause(Out, cpred(CPi))\n ; true\n ),\n portray_clause(Out, ':-'(Ci, Pi))\n ; true\n ),\n ( \\+cpred(CPi)\n -> assertz(cpred(CPi))\n ; true\n ),\n assertz(':-'(Ci, Pj))\n )\n ; ( Rt \\= implies(_, _, _),\n Rt \\= scount(_),\n \\+flag('no-distinct-input'),\n call(Rt)\n -> true\n ; ( Rt \\= pred('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>'),\n \\+ (Rt = scope(_), Mode = query)\n -> djiti_assertz(Rt),\n ( flag(intermediate, Out),\n Rt \\= scount(_)\n -> format(Out, '~q.~n', [Rt])\n ; true\n ),\n ( Rt \\= flag(_, _),\n Rt \\= scope(_),\n Rt \\= pfx(_, _),\n Rt \\= pred(_),\n Rt \\= cpred(_),\n Rt \\= scount(_)\n -> ( flag(nope)\n -> true\n ; term_index(true, Pnd),\n nb_getval(current_scope, Src),\n assertz(prfstep(Rt, true, Pnd, Rt, _, forward, Src))\n )\n ; true\n )\n ; true\n )\n )\n )\n ).\n\n% N3 to N3P compiler\n\nn3_n3p(Argument, Mode) :-\n absolute_uri(Argument, Arg),\n tmp_file(Tmp),\n ( wcacher(Arg, File)\n -> ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w FROM ~w ', [Arg, File]),\n flush_output(user_error)\n ),\n open(File, read, In, [encoding(utf8)])\n ; ( flag(quiet)\n -> true\n ; format(user_error, 'GET ~w ', [Arg]),\n flush_output(user_error)\n ),\n ( ( sub_atom(Arg, 0, 5, _, 'http:')\n -> true\n ; sub_atom(Arg, 0, 6, _, 'https:')\n )\n -> http_open(Arg, In, []),\n set_stream(In, encoding(utf8))\n ; ( sub_atom(Arg, 0, 5, _, 'file:')\n -> ( parse_url(Arg, Parts)\n -> memberchk(path(File), Parts)\n ; sub_atom(Arg, 7, _, 0, File)\n )\n ; File = Arg\n ),\n ( File = '-'\n -> In = user_input\n ; open(File, read, In, [encoding(utf8)])\n )\n )\n ),\n retractall(base_uri(_)),\n ( Arg = '-'\n -> absolute_uri('', Abu),\n assertz(base_uri(Abu))\n ; assertz(base_uri(Arg))\n ),\n retractall(ns(_, _)),\n ( Arg = '-'\n -> D = '#'\n ; atomic_list_concat([Arg, '#'], D)\n ),\n assertz(ns('', D)),\n retractall(quvar(_, _, _)),\n retractall(qevar(_, _, _)),\n retractall(evar(_, _, _)),\n nb_setval(line_number, 1),\n nb_setval(sc, 0),\n nb_setval(semantics, []),\n atomic_list_concat(['\\'<', Arg, '>\\''], Src),\n atomic_list_concat([Tmp, '_p'], Tmp_p),\n assertz(tmpfile(Tmp_p)),\n open(Tmp_p, write, Ws, [encoding(utf8)]),\n tell(Ws),\n catch(\n ( repeat,\n tokens(In, Tokens),\n phrase(document(Triples), Tokens, Rest),\n ( Rest = []\n -> true\n ; nb_getval(line_number, Ln),\n throw(invalid_document(after_line(Ln)))\n ),\n ( Mode = semantics\n -> nb_getval(semantics, TriplesPrev),\n append(TriplesPrev, Triples, TriplesNext),\n findall(Tr,\n ( member(Triple, TriplesNext),\n ( Triple = ':-'(Head, Body)\n -> Tr = '\\'<http://www.w3.org/2000/10/swap/log#implies>\\''(Body, Head)\n ; Tr = Triple\n )\n ),\n TriplesNext2\n ),\n nb_setval(semantics, TriplesNext2)\n ; tr_n3p(Triples, Src, Mode)\n ),\n Tokens = []\n ),\n Exc2,\n ( ( Mode = semantics\n -> told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n throw(Exc2)\n ; true\n ),\n ( wcacher(Arg, File)\n -> format(user_error, '** ERROR ** ~w FROM ~w ** ~w~n', [Arg, File, Exc2])\n ; format(user_error, '** ERROR ** ~w ** ~w~n', [Arg, Exc2])\n ),\n flush_output(user_error),\n nb_setval(exit_code, 1),\n ( ( \\+data_fuse,\n Mode == 'not-entail'\n ; data_fuse,\n Mode == entail\n )\n -> write(query(true, true)),\n writeln('.')\n ; true\n ),\n assertz(data_fuse)\n )\n ),\n ( Mode = semantics\n -> nb_getval(semantics, List),\n write(semantics(Src, List)),\n writeln('.')\n ; true\n ),\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n ( File = '-'\n -> true\n ; close(In)\n ),\n ( retract(tmpfile(Tmp))\n -> delete_file(Tmp)\n ; true\n ),\n ( flag(intermediate, Out)\n -> forall(\n ( pfx(Pp, Pu),\n \\+wpfx(Pp)\n ),\n ( portray_clause(Out, pfx(Pp, Pu)),\n assertz(wpfx(Pp))\n )\n )\n ; true\n ),\n open(Tmp_p, read, Rs, [encoding(utf8)]),\n ( Mode = semantics\n -> repeat,\n read(Rs, Rt),\n ( Rt = end_of_file\n -> true\n ; djiti_assertz(Rt),\n ( Rt = semantics(_, L)\n -> length(L, N),\n nb_setval(sc, N)\n ; Rt \\= semantics(_, []),\n nb_setval(sc, 1)\n ),\n fail\n )\n ; repeat,\n read(Rs, Rt),\n ( Rt = end_of_file\n -> true\n ; dynify(Rt),\n ( ground(Rt),\n Rt \\= ':-'(_, _)\n -> ( predicate_property(Rt, dynamic)\n -> true\n ; close(Rs),\n ( retract(tmpfile(Tmp_p))\n -> delete_file(Tmp_p)\n ; true\n ),\n throw(builtin_redefinition(Rt))\n ),\n ( Rt \\= implies(_, _, _),\n \\+flag('no-distinct-input'),\n call(Rt)\n -> true\n ; djiti_assertz(Rt),\n cnt(sc),\n ( flag(intermediate, Out)\n -> portray_clause(Out, Rt)\n ; true\n )\n )\n ; ( Rt = prfstep(Ct, Pt, _, Qt, It, Mt, St)\n -> term_index(Pt, Pnd),\n ( nonvar(It)\n -> copy_term_nat(It, Ic)\n ; Ic = It\n ),\n ( \\+prfstep(Ct, Pt, Pnd, Qt, Ic, Mt, St)\n -> assertz(prfstep(Ct, Pt, Pnd, Qt, Ic, Mt, St))\n ; true\n )\n ; ( Rt = ':-'(Ci, Px),\n ( Px = true\n -> functor(Ci, Cf, _),\n ( \\+pred(Cf),\n \\+cpred(Cf)\n -> assertz(pred(Cf))\n ; true\n )\n ; true\n ),\n conjify(Px, Pi)\n -> ( Ci = true\n -> ( flag(intermediate, Out)\n -> portray_clause(Out, ':-'(Pi))\n ; true\n ),\n ( flag('parse-only')\n -> true\n ; call(Pi)\n )\n ; atomic_list_concat(['<', Arg, '>'], Si),\n copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(Pi, Ci), Ri),\n ( flag(nope)\n -> Ph = Pi\n ; ( Pi = when(Ai, Bi)\n -> conj_append(Bi, istep(Si, Pi, Ci, Ri), Bh),\n Ph = when(Ai, Bh)\n ; conj_append(Pi, istep(Si, Pi, Ci, Ri), Ph)\n )\n ),\n ( flag('rule-histogram')\n -> ( Ph = when(Ak, Bk)\n -> conj_append(Bk, pstep(Ri), Bj),\n Pj = when(Ak, Bj)\n ; conj_append(Ph, pstep(Ri), Pj)\n )\n ; Pj = Ph\n ),\n cnt(sc),\n functor(Ci, CPi, _),\n ( flag(intermediate, Out)\n -> ( \\+cpred(CPi)\n -> portray_clause(Out, cpred(CPi))\n ; true\n ),\n portray_clause(Out, ':-'(Ci, Pi))\n ; true\n ),\n ( \\+cpred(CPi)\n -> assertz(cpred(CPi))\n ; true\n ),\n assertz(':-'(Ci, Pj))\n )\n ; djiti_assertz(Rt),\n cnt(sc),\n ( flag(intermediate, Out)\n -> portray_clause(Out, Rt)\n ; true\n )\n )\n )\n ),\n fail\n )\n ),\n close(Rs),\n ( retract(tmpfile(Tmp_p))\n -> delete_file(Tmp_p)\n ; true\n ),\n nb_getval(sc, SC),\n nb_getval(input_statements, IN),\n Inp is SC+IN,\n nb_setval(input_statements, Inp),\n ( flag(quiet)\n -> true\n ; format(user_error, 'SC=~w~n', [SC]),\n flush_output(user_error)\n ),\n !.\n\ntr_n3p([], _, _) :-\n !.\ntr_n3p(X, _, entail) :-\n !,\n conj_list(Y, X),\n write(query(Y, true)),\n writeln('.').\ntr_n3p(X, _, 'not-entail') :-\n !,\n conj_list(Y, X),\n write(query(\\+Y, true)),\n writeln('.').\ntr_n3p(['\\'<http://www.w3.org/2000/10/swap/log#implies>\\''(X, Y)|Z], Src, query) :-\n !,\n ( Y = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, T)\n -> ( is_list(T)\n -> H = T\n ; findvars(X, U, epsilon),\n distinct(U, H)\n ),\n nb_setval(csv_header, H),\n V = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, H)\n ; V = Y\n ),\n ( \\+flag('limited-answer', _),\n flag(nope),\n ( flag('no-distinct-output')\n ; V = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, _)\n )\n -> write(query(X, V)),\n writeln('.')\n ; djiti_answer(answer(V), A),\n write(implies(X, A, Src)),\n writeln('.')\n ),\n tr_n3p(Z, Src, query).\ntr_n3p([':-'(Y, X)|Z], Src, query) :-\n !,\n ( Y = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, T)\n -> ( is_list(T)\n -> H = T\n ; findvars(X, U, epsilon),\n distinct(U, H)\n ),\n nb_setval(csv_header, H),\n V = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, H)\n ; V = Y\n ),\n ( ( \\+flag('limited-answer', _)\n ; V = '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>\\''(_, _),\n flag(strings)\n ),\n flag(nope)\n -> write(query(X, V)),\n writeln('.')\n ; djiti_answer(answer(V), A),\n write(implies(X, A, Src)),\n writeln('.')\n ),\n tr_n3p(Z, Src, query).\ntr_n3p(['\\'<http://www.w3.org/2000/10/swap/log#implies>\\''(X, Y)|Z], Src, Mode) :-\n !,\n ( flag(tactic, 'linear-select')\n -> write(implies(X, '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>\\''(X, Y), Src)),\n writeln('.'),\n write(implies('\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>\\''(X, Y), Y, Src)),\n writeln('.')\n ; write(implies(X, Y, Src)),\n writeln('.')\n ),\n tr_n3p(Z, Src, Mode).\ntr_n3p([':-'(Y, X)|Z], Src, Mode) :-\n !,\n tr_tr(Y, U),\n write(':-'(U, X)),\n writeln('.'),\n tr_n3p(Z, Src, Mode).\ntr_n3p(['\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tactic>\\''(X, Y)|Z], Src, Mode) :-\n !,\n write('\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tactic>\\''(X, Y)),\n writeln('.'),\n tr_n3p(Z, Src, Mode).\ntr_n3p([X|Z], Src, Mode) :-\n ( X \\= '\\'<http://www.w3.org/2000/10/swap/reason#gives>\\''(_, _)\n -> tr_tr(X, Y)\n ; Y = X\n ),\n ( findvars(Y, U, epsilon),\n U = []\n -> write(Y),\n writeln('.'),\n ( flag(nope)\n -> true\n ; write(prfstep(Y, true, _, Y, _, forward, Src)),\n writeln('.')\n )\n ; write(':-'(Y, true)),\n writeln('.')\n ),\n tr_n3p(Z, Src, Mode).\n\ntr_tr([], []) :-\n !.\ntr_tr([A|B], [C|D]) :-\n !,\n tr_tr(A, C),\n tr_tr(B, D).\ntr_tr(A, B) :-\n atom(A),\n !,\n ( atom_concat('_', C, A),\n ( sub_atom(C, 0, _, _, 'bn_')\n ; sub_atom(C, 0, _, _, 'e_')\n )\n -> nb_getval(var_ns, Sns),\n atomic_list_concat(['\\'<', Sns, C, '>\\''], B)\n ; B = A\n ).\ntr_tr(A, A) :-\n number(A),\n !.\ntr_tr(A, B) :-\n A =.. [C|D],\n tr_tr(D, E),\n B =.. [C|E].\n\ntr_split([], [], []) :-\n !.\ntr_split([A|B], C, [A|D]) :-\n functor(A, '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>\\'', _),\n !,\n tr_split(B, C, D).\ntr_split([A|B], C, D) :-\n functor(A, '\\'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#true>\\'', _),\n !,\n tr_split(B, C, D).\ntr_split([A|B], [A|C], D) :-\n tr_split(B, C, D).\n\nttl_n3p(literal(type(A, B)), literal(B, type(A))) :-\n !.\nttl_n3p(literal(lang(A, B)), literal(B, lang(A))) :-\n !.\nttl_n3p(literal(A), literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n !.\nttl_n3p(node(A), B) :-\n !,\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'node_', A, '>'], B).\nttl_n3p(A, B) :-\n atomic_list_concat(['<', A, '>'], B).\n\n%\n% N3 parser\n%\n% according to http://www.w3.org/2000/10/swap/grammar/n3-ietf.txt\n% inspired by http://code.google.com/p/km-rdf/wiki/Henry\n%\n\nannotation(Triple, Triples) -->\n [lb_pipe],\n !,\n propertylist(Triple, Triples),\n { ( Triples \\= []\n -> true\n ; nb_getval(line_number, Ln),\n throw('empty_triple_annotation'(after_line(Ln)))\n )\n },\n [pipe_rb].\nannotation(_, []) -->\n [].\n\nbarename(BareName) -->\n [name(BareName)].\n\nbarename_csl([BareName|Tail]) -->\n barename(BareName),\n !,\n barename_csl_tail(Tail).\nbarename_csl([]) -->\n [].\n\nbarename_csl_tail([BareName|Tail]) -->\n [','],\n !,\n barename(BareName),\n barename_csl_tail(Tail).\nbarename_csl_tail([]) -->\n [].\n\nboolean(true) -->\n [name('true')],\n !.\nboolean(false) -->\n [name('false')],\n !.\nboolean(Boolean) -->\n literal(Atom, type(T)),\n { T = '\\'<http://www.w3.org/2001/XMLSchema#boolean>\\'',\n ( memberchk([Boolean, Atom], [[true, '\\'true\\''], [true, true], [true, '\\'1\\''], [false, '\\'false\\''], [false, false], [false, '\\'0\\'']])\n -> true\n ; ( flag('parse-only')\n -> true\n ; nb_getval(line_number, Ln),\n throw(invalid_boolean_literal(Atom, after_line(Ln)))\n )\n )\n }.\n\ndeclaration -->\n [atname(base)],\n !,\n explicituri(U),\n { base_uri(V),\n resolve_uri(U, V, URI),\n retractall(base_uri(_)),\n assertz(base_uri(URI))\n }.\ndeclaration -->\n [name(Name)],\n { downcase_atom(Name, 'base')\n },\n !,\n explicituri(U),\n { base_uri(V),\n resolve_uri(U, V, URI),\n retractall(base_uri(_)),\n assertz(base_uri(URI))\n },\n withoutdot.\ndeclaration -->\n [atname(prefix)],\n !,\n prefix(Prefix),\n explicituri(U),\n { base_uri(V),\n resolve_uri(U, V, URI),\n retractall(ns(Prefix, _)),\n assertz(ns(Prefix, URI)),\n put_pfx(Prefix, URI)\n }.\ndeclaration -->\n [name(Name)],\n { downcase_atom(Name, 'prefix')\n },\n prefix(Prefix),\n explicituri(U),\n { base_uri(V),\n resolve_uri(U, V, URI),\n retractall(ns(Prefix, _)),\n assertz(ns(Prefix, URI)),\n put_pfx(Prefix, URI)\n },\n withoutdot.\n\ndocument(Triples) -->\n statements_optional(Triples).\n\ndtlang(lang(Langcode)) -->\n [atname(Name)],\n { Name \\= 'is',\n Name \\= 'has'\n },\n !,\n { downcase_atom(Name, N),\n atomic_list_concat(['\\'', N, '\\''], Langcode)\n }.\ndtlang(type(Datatype)) -->\n [caret_caret],\n !,\n uri(Datatype).\ndtlang(type(T)) -->\n { T = '\\'<http://www.w3.org/2001/XMLSchema#string>\\''\n },\n [].\n\nexistential -->\n [atname(forSome)],\n !,\n symbol_csl(Symbols),\n { nb_getval(fdepth, D),\n forall(\n member(S, Symbols),\n ( gensym('qe_', Q),\n asserta(qevar(S, Q, D))\n )\n )\n }.\n\nexplicituri(ExplicitURI) -->\n [relative_uri(ExplicitURI)].\n\nexpression(Node, T) -->\n pathitem(N1, T1),\n pathtail(N1, Node, T2),\n { append(T1, T2, T)\n }.\n\nformulacontent(Formula) -->\n statementlist(List),\n { conj_list(Formula, List)\n }.\n\nliteral(Atom, DtLang) -->\n string(Codes),\n dtlang(DtLang),\n { escape_string(Codes, B),\n escape_string(B, C),\n atom_codes(A, C),\n ( sub_atom(A, _, 1, _, '\\'')\n -> escape_squote(C, D),\n atom_codes(E, D)\n ; E = A\n ),\n atomic_list_concat(['\\'', E, '\\''], Atom)\n }.\n\nnumericliteral(Number) -->\n [numeric(_, NumB)],\n { numeral(NumB, NumC),\n number_codes(Number, NumC)\n }.\n\nobject(Node, Triples) -->\n expression(Node, Triples).\n\nobjecttail(Subject, Verb, [Triple|Triples]) -->\n [','],\n !,\n object(Object, Triples1),\n { ( Verb = isof(Vrb)\n -> Trpl = triple(Object, Vrb, Subject)\n ; Trpl = triple(Subject, Verb, Object)\n )\n },\n annotation(Trpl, Triples2),\n objecttail(Subject, Verb, Triples3),\n { append([Triples1, Triples2, Triples3], Triples),\n ( Verb = isof(V)\n -> ( atom(V),\n \\+sub_atom(V, 0, 1, _, '_')\n -> Triple =.. [V, Object, Subject]\n ; Triple = exopred(V, Object, Subject)\n )\n ; ( atom(Verb),\n \\+sub_atom(Verb, 0, 1, _, '_')\n -> Triple =.. [Verb, Subject, Object]\n ; Triple = exopred(Verb, Subject, Object)\n )\n )\n }.\nobjecttail(_, _, []) -->\n [].\n\npathitem(Name, []) -->\n symbol(S),\n !,\n { ( qevar(S, N, D),\n \\+quvar(S, _, _)\n -> ( D = 1,\n nb_getval(fdepth, FD),\n FD >= D,\n \\+flag('pass-all-ground')\n -> atom_concat('_', N, Name)\n ; atomic_list_concat(['\\'<http://eyereasoner.github.io/var#', N, '>\\''], Name),\n ( pfx('var:', _)\n -> true\n ; assertz(pfx('var:', '<http://eyereasoner.github.io/var#>'))\n )\n )\n ; ( quvar(S, N, D)\n -> ( nb_getval(fdepth, FD),\n FD >= D,\n \\+flag('pass-all-ground')\n -> atom_concat('_', N, Name)\n ; atomic_list_concat(['\\'<http://eyereasoner.github.io/var#', N, '>\\''], Name),\n ( pfx('var:', _)\n -> true\n ; assertz(pfx('var:', '<http://eyereasoner.github.io/var#>'))\n )\n )\n ; Name = S\n )\n )\n }.\npathitem(VarID, []) -->\n [uvar(Var)],\n !,\n { atom_codes(Var, VarCodes),\n subst([[[0'-], [0'_, 0'M, 0'I, 0'N, 0'U, 0'S, 0'_]], [[0'.], [0'_, 0'D, 0'O, 0'T, 0'_]]], VarCodes, VarTidy),\n atom_codes(VarAtom, [0'_|VarTidy]),\n ( flag('pass-all-ground')\n -> nb_getval(var_ns, Sns),\n atom_codes(VarFrag, VarTidy),\n atomic_list_concat(['\\'<', Sns, VarFrag, '>\\''], VarID)\n ; VarID = VarAtom\n )\n }.\npathitem(Number, []) -->\n numericliteral(Number),\n !.\npathitem(Boolean, []) -->\n boolean(Boolean),\n !.\npathitem(Atom, []) -->\n literal(A, type(T)),\n { T = '\\'<http://eulersharp.sourceforge.net/2003/03swap/prolog#atom>\\''\n },\n !,\n { atom_codes(A, B),\n escape_string(C, B),\n atom_codes(Atom, C)\n }.\npathitem(Number, [], L1, L2) :-\n literal(Atom, type(Type), L1, L2),\n nb_getval(fdepth, 0),\n memberchk(Type, ['\\'<http://www.w3.org/2001/XMLSchema#integer>\\'', '\\'<http://www.w3.org/2001/XMLSchema#long>\\'', '\\'<http://www.w3.org/2001/XMLSchema#decimal>\\'', '\\'<http://www.w3.org/2001/XMLSchema#double>\\'']),\n sub_atom(Atom, 1, _, 1, A),\n atom_codes(A, NumB),\n numeral(NumB, NumC),\n number_codes(Number, NumC),\n !.\npathitem(literal(Atom, DtLang), []) -->\n literal(Atom, DtLang),\n !.\npathitem(Subject, Triples) -->\n ['[',name(id)],\n !,\n expression(Subject, T1),\n propertylist(Subject, T2),\n { append(T1, T2, Triples)\n },\n [']'].\npathitem(Node, Triples) -->\n ['['],\n !,\n { gensym('bn_', S),\n ( ( nb_getval(entail_mode, false),\n nb_getval(fdepth, 0)\n ; flag('pass-all-ground')\n )\n -> nb_getval(var_ns, Sns),\n atomic_list_concat(['\\'<', Sns, S, '>\\''], BN)\n ; atom_concat('_', S, BN)\n )\n },\n propertylist(BN, T),\n { ( memberchk('\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>\\''(X, Head), T),\n memberchk('\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>\\''(X, Tail), T),\n del(T, '\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>\\''(X, '\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#List>\\''), U),\n del(U, '\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>\\''(X, Head), V),\n del(V, '\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>\\''(X, Tail), W)\n -> Node = [Head|Tail],\n Triples = W\n ; Node = BN,\n Triples = T\n )\n },\n [']'].\npathitem(set(Distinct), Triples) -->\n ['(', '$'],\n !,\n pathlist(List, Triples),\n { sort(List, Distinct)\n },\n ['$', ')'].\npathitem(List, Triples) -->\n ['('],\n !,\n pathlist(List, Triples),\n [')'].\npathitem(triple(S, P, O), []) -->\n [lt_lt],\n !,\n subject(S, []),\n verb(P, []),\n object(O, []),\n [gt_gt].\npathitem(Node, []) -->\n ['{'],\n { nb_getval(fdepth, I),\n J is I+1,\n nb_setval(fdepth, J)\n },\n formulacontent(Node),\n { retractall(quvar(_, _, J)),\n retractall(qevar(_, _, J)),\n retractall(evar(_, _, J)),\n nb_setval(fdepth, I),\n ( nb_getval(entail_mode, true)\n -> nb_getval(line_number, Ln),\n throw(non_rdf_entailment(Node, after_line(Ln)))\n ; true\n )\n },\n ['}'].\n\npathlist([Node|Rest], Triples) -->\n expression(Node, T),\n !,\n pathlist(Rest, Tail),\n { append(T, Tail, Triples)\n }.\npathlist([], []) -->\n [].\n\npathtail(Node, PNode, [Triple|Triples]) -->\n ['!'],\n !,\n pathitem(Item, Triples2),\n { prolog_verb(Item, Verb),\n gensym('bn_', S),\n ( ( nb_getval(fdepth, 0)\n ; flag('pass-all-ground')\n )\n -> nb_getval(var_ns, Sns),\n atomic_list_concat(['\\'<', Sns, S, '>\\''], BNode)\n ; atom_concat('_', S, BNode)\n ),\n ( Verb = isof(V)\n -> ( atom(V),\n \\+sub_atom(V, 0, 1, _, '_')\n -> Triple =.. [V, BNode, Node]\n ; Triple = exopred(V, BNode, Node)\n )\n ; ( Verb = prolog:Pred\n -> ( BNode = true\n -> Triple =.. [Pred|Node]\n ; ( BNode = false\n -> T =.. [Pred|Node],\n Triple = \\+(T)\n ; ( prolog_sym(_, Pred, func)\n -> T =.. [Pred|Node],\n Triple = is(BNode, T)\n ; Triple =.. [Pred, Node, BNode]\n )\n )\n )\n ; ( atom(Verb),\n \\+sub_atom(Verb, 0, 1, _, '_')\n -> Triple =.. [Verb, Node, BNode]\n ; Triple = exopred(Verb, Node, BNode)\n )\n )\n )\n },\n pathtail(BNode, PNode, Tail),\n { append(Triples2, Tail, Triples)\n }.\npathtail(Node, PNode, [Triple|Triples]) -->\n ['^'],\n !,\n pathitem(Item, Triples2),\n { prolog_verb(Item, Verb),\n gensym('bn_', S),\n ( ( nb_getval(fdepth, 0)\n ; flag('pass-all-ground')\n )\n -> nb_getval(var_ns, Sns),\n atomic_list_concat(['\\'<', Sns, S, '>\\''], BNode)\n ; atom_concat('_', S, BNode)\n ),\n ( Verb = isof(V)\n -> ( atom(V),\n \\+sub_atom(V, 0, 1, _, '_')\n -> Triple =.. [V, Node, BNode]\n ; Triple = exopred(V, Node, BNode)\n )\n ; ( Verb = prolog:Pred\n -> ( Node = true\n -> Triple =.. [Pred|BNode]\n ; ( Node = false\n -> T =.. [Pred|BNode],\n Triple = \\+(T)\n ; ( prolog_sym(_, Pred, func)\n -> T =.. [Pred|BNode],\n Triple = is(Node, T)\n ; Triple =.. [Pred, BNode, Node]\n )\n )\n )\n ; ( atom(Verb),\n \\+sub_atom(Verb, 0, 1, _, '_')\n -> Triple =.. [Verb, BNode, Node]\n ; Triple = exopred(Verb, BNode, Node)\n )\n )\n )\n },\n pathtail(BNode, PNode, Tail),\n { append(Triples2, Tail, Triples)\n }.\npathtail(Node, Node, []) -->\n [].\n\nprefix(Prefix) -->\n [Prefix:''].\n\npropertylist(Subject, [Triple|Triples]) -->\n verb(Item, Triples1),\n { prolog_verb(Item, Verb),\n ( Verb = '\\'<http://www.w3.org/2000/10/swap/log#implies>\\''\n -> nb_setval(mconc, true)\n ; true\n )\n },\n !,\n object(Object, Triples2),\n { ( Verb = isof(Vrb)\n -> Trpl = triple(Object, Vrb, Subject)\n ; Trpl = triple(Subject, Verb, Object)\n ),\n ( Verb = '\\'<http://www.w3.org/2000/10/swap/log#implies>\\''\n -> nb_setval(mconc, false)\n ; true\n )\n },\n annotation(Trpl, Triples3),\n objecttail(Subject, Verb, Triples4),\n propertylisttail(Subject, Triples5),\n { append([Triples1, Triples2, Triples3, Triples4, Triples5], Triples),\n ( Verb = isof(V)\n -> ( atom(V),\n \\+sub_atom(V, 0, 1, _, '_')\n -> Triple =.. [V, Object, Subject]\n ; Triple = exopred(V, Object, Subject)\n )\n ; ( Verb = prolog:Pred\n -> ( Object = true\n -> Triple =.. [Pred|Subject]\n ; ( Object = false\n -> T =.. [Pred|Subject],\n Triple = \\+(T)\n ; ( prolog_sym(_, Pred, func)\n -> T =.. [Pred|Subject],\n Triple = is(Object, T)\n ; Triple =.. [Pred, Subject, Object]\n )\n )\n )\n ; ( atom(Verb),\n \\+sub_atom(Verb, 0, 1, _, '_')\n -> Triple =.. [Verb, Subject, Object]\n ; Triple = exopred(Verb, Subject, Object)\n )\n )\n )\n }.\npropertylist(_, []) -->\n [].\n\npropertylisttail(Subject, Triples) -->\n [';'],\n !,\n propertylisttailsemis,\n propertylist(Subject, Triples).\npropertylisttail(_, []) -->\n [].\n\npropertylisttailsemis -->\n [';'],\n !,\n propertylisttailsemis.\npropertylisttailsemis -->\n [].\n\nqname(URI) -->\n [NS:Name],\n { ( ns(NS, Base)\n -> atomic_list_concat([Base, Name], Name1),\n ( sub_atom(Name1, _, 1, _, '\\'')\n -> atom_codes(Name1, Codes1),\n escape_squote(Codes1, Codes2),\n atom_codes(Name2, Codes2)\n ; Name2 = Name1\n ),\n atomic_list_concat(['\\'<', Name2, '>\\''], URI)\n ; nb_getval(line_number, Ln),\n throw(no_prefix_directive(NS, after_line(Ln)))\n )\n },\n !.\n\nsimpleStatement(Triples) -->\n subject(Subject, Triples1),\n ( { Subject = (D1;D2)\n }\n -> { Triples = [(D1;D2)]\n }\n ; propertylist(Subject, Triples2),\n { append(Triples1, Triples2, Triples)\n }\n ).\n\nstatement([]) -->\n declaration,\n !.\nstatement([]) -->\n universal,\n !.\nstatement([]) -->\n existential,\n !.\nstatement(Statement) -->\n simpleStatement(Statement).\n\nstatementlist(Triples) -->\n statement(Tr),\n !,\n statementtail(T),\n { append(Tr, T, Triples)\n }.\nstatementlist([]) -->\n [].\n\nstatements_optional(Triples) -->\n statement(Tr),\n [dot(Ln)],\n !,\n { nb_setval(line_number, Ln)\n },\n statements_optional(T),\n { append(Tr, T, Triples)\n }.\nstatements_optional([]) -->\n [].\n\nstatementtail(T) -->\n [dot(Ln)],\n !,\n { nb_setval(line_number, Ln)\n },\n statementlist(T).\nstatementtail([]) -->\n [].\n\nstring(Codes) -->\n [literal(Codes)].\n\nsubject(Node, Triples) -->\n expression(Node, Triples).\n\nsymbol(Name) -->\n uri(Name),\n !.\nsymbol(Name) -->\n [name(N)],\n !,\n { ( memberchk(N, [true, false])\n -> Name = N\n ; nb_getval(line_number, Ln),\n throw(invalid_keyword(N, after_line(Ln)))\n )\n }.\nsymbol(Name) -->\n [bnode(Lb)],\n { ( nb_getval(mconc, true)\n -> atom_concat(Lb, '_c', Label)\n ; Label = Lb\n ),\n ( evar(Label, S, 0)\n -> true\n ; atom_concat(Label, '_', M),\n gensym(M, S),\n assertz(evar(Label, S, 0))\n ),\n ( ( nb_getval(entail_mode, false),\n nb_getval(fdepth, 0)\n ; flag('pass-all-ground')\n )\n -> nb_getval(var_ns, Sns),\n ( flag('pass-all-ground')\n -> atomic_list_concat(['\\'<', Sns, Label, '>\\''], Name)\n ; atomic_list_concat(['\\'<', Sns, 'e_', S, '>\\''], Name)\n )\n ; atom_concat('_e_', S, Name)\n )\n }.\n\nsymbol_csl([Symbol|Tail]) -->\n symbol(Symbol),\n !,\n symbol_csl_tail(Tail).\nsymbol_csl([]) -->\n [].\n\nsymbol_csl_tail([Symbol|T]) -->\n [','],\n !,\n symbol(Symbol),\n symbol_csl_tail(T).\nsymbol_csl_tail([]) -->\n [].\n\nuniversal -->\n [atname(forAll)],\n !,\n symbol_csl(Symbols),\n { nb_getval(fdepth, D),\n forall(\n member(S, Symbols),\n ( gensym('qu_', Q),\n asserta(quvar(S, Q, D))\n )\n )\n }.\n\nuri(Name) -->\n explicituri(U),\n !,\n { base_uri(V),\n resolve_uri(U, V, W),\n ( sub_atom(W, _, 1, _, '\\'')\n -> atom_codes(W, X),\n escape_squote(X, Y),\n atom_codes(Z, Y)\n ; Z = W\n ),\n atomic_list_concat(['\\'<', Z, '>\\''], Name)\n }.\nuri(Name) -->\n qname(Name).\n\nverb('\\'<http://www.w3.org/2000/10/swap/log#implies>\\'', []) -->\n ['=', '>'],\n !.\nverb('\\'<http://www.w3.org/2002/07/owl#sameAs>\\'', []) -->\n ['='],\n !.\nverb(':-', []) -->\n [lt_eq],\n !.\nverb('\\'<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>\\'', []) -->\n [name(a)],\n !.\nverb(Node, Triples) -->\n [name(has)],\n !,\n expression(Node, Triples).\nverb(isof(Node), Triples) -->\n [name(is)],\n !,\n expression(Node, Triples),\n [name(of)].\nverb(isof(Node), Triples) -->\n [lt_dash],\n !,\n expression(Node, Triples).\nverb(Node, Triples) -->\n expression(Node, Triples).\n\nwithoutdot, [dot(Ln)] -->\n [dot(Ln)],\n !,\n { throw(unexpected_dot(after_line(Ln)))\n }.\nwithoutdot, [dot(Ln)] -->\n [],\n { nb_getval(line_number, Ln)\n }.\n\n%\n% N3 tokenizer\n%\n\ntokens(In, List) :-\n get_code(In, C0),\n ( token(C0, In, C1, Tok1)\n -> true\n ; nb_getval(line_number, Ln),\n char_code(Char, C0),\n throw(illegal_token(char_code(Char, C0), line(Ln)))\n ),\n ( Tok1 == end_of_file\n -> List = []\n ; List = [Tok1|Tokens],\n tokens(C1, In, Tokens)\n ).\n\ntokens(C0, In, List) :-\n ( token(C0, In, C1, H)\n -> true\n ; nb_getval(line_number, Ln),\n char_code(Char, C0),\n throw(illegal_token(char_code(Char, C0), line(Ln)))\n ),\n ( H == end_of_file\n -> List = []\n ; List = [H|T],\n tokens(C1, In, T)\n ).\n\ntoken(-1, _, -1, end_of_file) :-\n !.\ntoken(0'., In, C, Token) :-\n ( peek_code(In, C0),\n ( e(C0)\n -> T1 = [0'0|T2],\n get_code(In, CN1)\n ; 0'0 =< C0,\n C0 =< 0'9,\n get_code(In, C1),\n integer_codes(C1, In, CN1, T1, T2)\n )\n -> ( exponent(CN1, In, C, T2)\n -> Type = double\n ; C = CN1,\n T2 = [],\n Type = decimal\n ),\n Token = numeric(Type, [0'0, 0'.|T1])\n ; nb_getval(line_number, Ln),\n get_code(In, C),\n !,\n Token = dot(Ln)\n ).\ntoken(0'#, In, C, Token) :-\n !,\n get_code(In, C1),\n skip_line(C1, In, C2),\n token(C2, In, C, Token).\ntoken(C0, In, C, Token) :-\n white_space(C0),\n !,\n get_code(In, C1),\n token(C1, In, C, Token).\ntoken(C0, In, C, Number) :-\n 0'0 =< C0,\n C0 =< 0'9,\n !,\n number_n(C0, In, C, Number).\ntoken(0'-, In, C, Number) :-\n !,\n number_n(0'-, In, C, Number).\ntoken(0'+, In, C, Number) :-\n !,\n number_n(0'+, In, C, Number).\ntoken(0'\", In, C, literal(Codes)) :-\n !,\n ( peek_code(In, 0'\")\n -> get_code(In, 0'\"),\n ( peek_code(In, 0'\")\n -> get_code(In, 0'\"),\n get_code(In, C1),\n dq_string(C1, In, C, Codes)\n ; get_code(In, C),\n Codes = []\n )\n ; get_code(In, C1),\n string_dq(C1, In, C, Codes)\n ).\ntoken(0'', In, C, literal(Codes)) :-\n !,\n ( peek_code(In, 0'')\n -> get_code(In, 0''),\n ( peek_code(In, 0'')\n -> get_code(In, 0''),\n get_code(In, C1),\n sq_string(C1, In, C, Codes)\n ; get_code(In, C),\n Codes = []\n )\n ; get_code(In, C1),\n string_sq(C1, In, C, Codes)\n ).\ntoken(0'?, In, C, uvar(Name)) :-\n !,\n get_code(In, C0),\n ( name(C0, In, C, Name)\n -> true\n ; C = C0,\n nb_getval(line_number, Ln),\n throw(empty_quickvar_name(line(Ln)))\n ).\ntoken(0'_, In, C, bnode(Name)) :-\n peek_code(In, 0':),\n !,\n get_code(In, _),\n get_code(In, C0),\n ( name(C0, In, C, Name)\n -> true\n ; C = C0,\n Name = ''\n ).\ntoken(0'<, In, C, lt_lt) :-\n peek_code(In, 0'<),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0'<, In, C, lt_eq) :-\n peek_string(In, 2, D),\n string_codes(D, [0'=, E]),\n ( white_space(E)\n ; punctuation(E, _)\n ),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0'<, In, C, lt_dash) :-\n peek_code(In, 0'-),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0'<, In, C, relative_uri(URI)) :-\n peek_code(In, C1),\n !,\n get_code(In, C1),\n iri_chars(C1, In, C, Codes),\n D = Codes,\n atom_codes(URI, D).\ntoken(0'>, In, C, gt_gt) :-\n peek_code(In, 0'>),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0'{, In, C, lb_pipe) :-\n peek_code(In, 0'|),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0'|, In, C, pipe_rb) :-\n peek_code(In, 0'}),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(0':, In, C, Token) :-\n !,\n get_code(In, C0),\n ( local_name(C0, In, C, Name)\n -> Token = '':Name\n ; Token = '':'',\n C = C0\n ).\ntoken(0'@, In, C, atname(Name)) :-\n get_code(In, C0),\n token(C0, In, C, name(Name)),\n !.\ntoken(0'^, In, C, caret_caret) :-\n peek_code(In, 0'^),\n !,\n get_code(In, _),\n get_code(In, C).\ntoken(C0, In, C, Token) :-\n name(C0, In, C1, Name),\n !,\n ( C1 == 0':\n -> get_code(In, C2),\n ( local_name(C2, In, C, Name2)\n -> Token = (Name:Name2)\n ; Token = (Name:''),\n C = C2\n )\n ; Token = name(Name),\n C = C1\n ).\ntoken(C0, In, C, P) :-\n punctuation(C0, P),\n !,\n get_code(In, C).\n\nnumber_n(0'-, In, CN, numeric(T, [0'-|Codes])) :-\n !,\n get_code(In, C0),\n number_nn(C0, In, CN, numeric(T, Codes)).\nnumber_n(0'+, In, CN, numeric(T, [0'+|Codes])) :-\n !,\n get_code(In, C0),\n number_nn(C0, In, CN, numeric(T, Codes)).\nnumber_n(C0, In, CN, Value) :-\n number_nn(C0, In, CN, Value).\n\nnumber_nn(C, In, CN, numeric(Type, Codes)) :-\n integer_codes(C, In, CN0, Codes, T0),\n ( CN0 == 0'.,\n peek_code(In, C0),\n ( e(C0)\n -> T1 = [0'0|T2],\n get_code(In, CN1)\n ; 0'0 =< C0,\n C0 =< 0'9,\n get_code(In, C1),\n integer_codes(C1, In, CN1, T1, T2)\n ),\n T0 = [0'.|T1]\n -> ( exponent(CN1, In, CN, T2)\n -> Type = double\n ; CN = CN1,\n T2 = [],\n Type = decimal\n )\n ; ( exponent(CN0, In, CN, T0)\n -> Type = double\n ; T0 = [],\n CN = CN0,\n Type = integer\n )\n ).\n\ninteger_codes(C0, In, CN, [C0|T0], T) :-\n 0'0 =< C0,\n C0 =< 0'9,\n !,\n get_code(In, C1),\n integer_codes(C1, In, CN, T0, T).\ninteger_codes(CN, _, CN, T, T).\n\nexponent(C0, In, CN, [C0|T0]) :-\n e(C0),\n !,\n get_code(In, C1),\n optional_sign(C1, In, CN0, T0, T1),\n integer_codes(CN0, In, CN, T1, []),\n ( T1 = []\n -> nb_getval(line_number, Ln),\n throw(invalid_exponent(line(Ln)))\n ; true\n ).\n\noptional_sign(C0, In, CN, [C0|T], T) :-\n sign(C0),\n !,\n get_code(In, CN).\noptional_sign(CN, _, CN, T, T).\n\ne(0'e).\ne(0'E).\n\nsign(0'-).\nsign(0'+).\n\ndq_string(-1, _, _, []) :-\n !,\n nb_getval(line_number, Ln),\n throw(unexpected_end_of_input(line(Ln))).\ndq_string(0'\", In, C, []) :-\n ( retract(got_dq)\n -> true\n ; peek_code(In, 0'\"),\n get_code(In, _)\n ),\n ( retract(got_dq)\n -> assertz(got_dq)\n ; assertz(got_dq),\n peek_code(In, 0'\"),\n get_code(In, _),\n assertz(got_dq)\n ),\n !,\n ( peek_code(In, 0'\")\n -> nb_getval(line_number, Ln),\n throw(unexpected_double_quote(line(Ln)))\n ; true\n ),\n retractall(got_dq),\n get_code(In, C).\ndq_string(0'\", In, C, [0'\"|T]) :-\n !,\n ( retract(got_dq)\n -> C1 = 0'\"\n ; get_code(In, C1)\n ),\n dq_string(C1, In, C, T).\ndq_string(0'\\\\, In, C, [H|T]) :-\n ( retract(got_dq)\n -> C1 = 0'\"\n ; get_code(In, C1)\n ),\n !,\n string_escape(C1, In, C2, H),\n dq_string(C2, In, C, T).\ndq_string(C0, In, C, [C0|T]) :-\n ( retract(got_dq)\n -> C1 = 0'\"\n ; get_code(In, C1)\n ),\n dq_string(C1, In, C, T).\n\nsq_string(-1, _, _, []) :-\n !,\n nb_getval(line_number, Ln),\n throw(unexpected_end_of_input(line(Ln))).\nsq_string(0'', In, C, []) :-\n ( retract(got_sq)\n -> true\n ; peek_code(In, 0''),\n get_code(In, _)\n ),\n ( retract(got_sq)\n -> assertz(got_sq)\n ; assertz(got_sq),\n peek_code(In, 0''),\n get_code(In, _),\n assertz(got_sq)\n ),\n !,\n ( peek_code(In, 0'')\n -> nb_getval(line_number, Ln),\n throw(unexpected_single_quote(line(Ln)))\n ; true\n ),\n retractall(got_sq),\n get_code(In, C).\nsq_string(0'', In, C, [0''|T]) :-\n !,\n ( retract(got_sq)\n -> C1 = 0''\n ; get_code(In, C1)\n ),\n sq_string(C1, In, C, T).\nsq_string(0'\\\\, In, C, [H|T]) :-\n ( retract(got_sq)\n -> C1 = 0''\n ; get_code(In, C1)\n ),\n !,\n string_escape(C1, In, C2, H),\n sq_string(C2, In, C, T).\nsq_string(C0, In, C, [C0|T]) :-\n ( retract(got_sq)\n -> C1 = 0''\n ; get_code(In, C1)\n ),\n sq_string(C1, In, C, T).\n\nstring_dq(-1, _, _, []) :-\n !,\n nb_getval(line_number, Ln),\n throw(unexpected_end_of_input(line(Ln))).\nstring_dq(0'\\n, _, _, []) :-\n !,\n nb_getval(line_number, Ln),\n throw(unexpected_end_of_line(line(Ln))).\nstring_dq(0'\", In, C, []) :-\n !,\n get_code(In, C).\nstring_dq(0'\\\\, In, C, D) :-\n get_code(In, C1),\n !,\n string_escape(C1, In, C2, H),\n ( current_prolog_flag(windows, true),\n H > 0xFFFF\n -> E is (H-0x10000)>>10+0xD800,\n F is (H-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [H|T]\n ),\n string_dq(C2, In, C, T).\nstring_dq(C0, In, C, D) :-\n ( current_prolog_flag(windows, true),\n C0 > 0xFFFF\n -> E is (C0-0x10000)>>10+0xD800,\n F is (C0-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [C0|T]\n ),\n get_code(In, C1),\n string_dq(C1, In, C, T).\n\nstring_sq(-1, _, _, []) :-\n !,\n nb_getval(line_number, Ln),\n throw(unexpected_end_of_input(line(Ln))).\nstring_sq(0'', In, C, []) :-\n !,\n get_code(In, C).\nstring_sq(0'\\\\, In, C, D) :-\n get_code(In, C1),\n !,\n string_escape(C1, In, C2, H),\n ( current_prolog_flag(windows, true),\n H > 0xFFFF\n -> E is (H-0x10000)>>10+0xD800,\n F is (H-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [H|T]\n ),\n string_sq(C2, In, C, T).\nstring_sq(C0, In, C, D) :-\n ( current_prolog_flag(windows, true),\n C0 > 0xFFFF\n -> E is (C0-0x10000)>>10+0xD800,\n F is (C0-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [C0|T]\n ),\n get_code(In, C1),\n string_sq(C1, In, C, T).\n\nstring_escape(0't, In, C, 0'\\t) :-\n !,\n get_code(In, C).\nstring_escape(0'b, In, C, 0'\\b) :-\n !,\n get_code(In, C).\nstring_escape(0'n, In, C, 0'\\n) :-\n !,\n get_code(In, C).\nstring_escape(0'r, In, C, 0'\\r) :-\n !,\n get_code(In, C).\nstring_escape(0'f, In, C, 0'\\f) :-\n !,\n get_code(In, C).\nstring_escape(0'\", In, C, 0'\") :-\n !,\n get_code(In, C).\nstring_escape(0'', In, C, 0'') :-\n !,\n get_code(In, C).\nstring_escape(0'\\\\, In, C, 0'\\\\) :-\n !,\n get_code(In, C).\nstring_escape(0'u, In, C, Code) :-\n !,\n get_hhhh(In, A),\n ( 0xD800 =< A,\n A =< 0xDBFF\n -> get_code(In, 0'\\\\),\n get_code(In, 0'u),\n get_hhhh(In, B),\n Code is 0x10000+(A-0xD800)*0x400+(B-0xDC00)\n ; Code is A\n ),\n get_code(In, C).\nstring_escape(0'U, In, C, Code) :-\n !,\n get_hhhh(In, Code0),\n get_hhhh(In, Code1),\n Code is Code0 << 16 + Code1,\n get_code(In, C).\nstring_escape(C, _, _, _) :-\n nb_getval(line_number, Ln),\n atom_codes(A, [0'\\\\, C]),\n throw(illegal_string_escape_sequence(A, line(Ln))).\n\nget_hhhh(In, Code) :-\n get_code(In, C1),\n code_type(C1, xdigit(D1)),\n get_code(In, C2),\n code_type(C2, xdigit(D2)),\n get_code(In, C3),\n code_type(C3, xdigit(D3)),\n get_code(In, C4),\n code_type(C4, xdigit(D4)),\n Code is D1<<12+D2<<8+D3<<4+D4.\n\nlanguage(C0, In, C, [C0|Codes]) :-\n code_type(C0, lower),\n get_code(In, C1),\n lwr_word(C1, In, C2, Codes, Tail),\n sub_langs(C2, In, C, Tail, []).\n\nlwr_word(C0, In, C, [C0|T0], T) :-\n code_type(C0, lower),\n !,\n get_code(In, C1),\n lwr_word(C1, In, C, T0, T).\nlwr_word(C, _, C, T, T).\n\nsub_langs(0'-, In, C, [0'-, C1|Codes], T) :-\n get_code(In, C1),\n lwrdig(C1),\n !,\n get_code(In, C2),\n lwrdigs(C2, In, C3, Codes, Tail),\n sub_langs(C3, In, C, Tail, T).\nsub_langs(C, _, C, T, T).\n\nlwrdig(C) :-\n code_type(C, lower),\n !.\nlwrdig(C) :-\n code_type(C, digit).\n\nlwrdigs(C0, In, C, [C0|T0], T) :-\n lwrdig(C0),\n !,\n get_code(In, C1),\n lwr_word(C1, In, C, T0, T).\nlwrdigs(C, _, C, T, T).\n\niri_chars(0'>, In, C, []) :-\n !,\n get_code(In, C).\niri_chars(0'\\\\, In, C, D) :-\n !,\n get_code(In, C1),\n iri_escape(C1, In, C2, H),\n \\+non_iri_char(H),\n ( current_prolog_flag(windows, true),\n H > 0xFFFF\n -> E is (H-0x10000)>>10+0xD800,\n F is (H-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [H|T]\n ),\n iri_chars(C2, In, C, T).\niri_chars(0'%, In, C, [0'%, C1, C2|T]) :-\n !,\n get_code(In, C1),\n code_type(C1, xdigit(_)),\n get_code(In, C2),\n code_type(C2, xdigit(_)),\n get_code(In, C3),\n iri_chars(C3, In, C, T).\niri_chars(-1, _, _, _) :-\n !,\n fail.\niri_chars(C0, In, C, D) :-\n \\+non_iri_char(C0),\n ( current_prolog_flag(windows, true),\n C0 > 0xFFFF\n -> E is (C0-0x10000)>>10+0xD800,\n F is (C0-0x10000) mod 0x400+0xDC00,\n D = [E, F|T]\n ; D = [C0|T]\n ),\n get_code(In, C1),\n iri_chars(C1, In, C, T).\n\niri_escape(0'u, In, C, Code) :-\n !,\n get_hhhh(In, A),\n ( 0xD800 =< A,\n A =< 0xDBFF\n -> get_code(In, 0'\\\\),\n get_code(In, 0'u),\n get_hhhh(In, B),\n Code is 0x10000+(A-0xD800)*0x400+(B-0xDC00)\n ; Code is A\n ),\n get_code(In, C).\niri_escape(0'U, In, C, Code) :-\n !,\n get_hhhh(In, Code0),\n get_hhhh(In, Code1),\n Code is Code0 << 16 + Code1,\n get_code(In, C).\niri_escape(C, _, _, _) :-\n nb_getval(line_number, Ln),\n atom_codes(A, [0'\\\\, C]),\n throw(illegal_iri_escape_sequence(A, line(Ln))).\n\nnon_iri_char(C) :-\n 0x00 =< C,\n C =< 0x20,\n !.\nnon_iri_char(0'<).\nnon_iri_char(0'>).\nnon_iri_char(0'\").\nnon_iri_char(0'{).\nnon_iri_char(0'}).\nnon_iri_char(0'|).\nnon_iri_char(0'^).\nnon_iri_char(0'`).\nnon_iri_char(0'\\\\).\n\nname(C0, In, C, Atom) :-\n name_start_char(C0),\n get_code(In, C1),\n name_chars(C1, In, C, T),\n atom_codes(Atom, [C0|T]).\n\nname_start_char(C) :-\n pn_chars_base(C),\n !.\nname_start_char(0'_).\nname_start_char(C) :-\n code_type(C, digit).\n\nname_chars(0'., In, C, [0'.|T]) :-\n peek_code(In, C1),\n pn_chars(C1),\n !,\n get_code(In, C1),\n name_chars(C1, In, C, T).\nname_chars(C0, In, C, [C0|T]) :-\n pn_chars(C0),\n !,\n get_code(In, C1),\n name_chars(C1, In, C, T).\nname_chars(C, _, C, []).\n\npn_chars_base(C) :-\n code_type(C, alpha),\n !.\npn_chars_base(C) :-\n 0xC0 =< C,\n C =< 0xD6,\n !.\npn_chars_base(C) :-\n 0xD8 =< C,\n C =< 0xF6,\n !.\npn_chars_base(C) :-\n 0xF8 =< C,\n C =< 0x2FF,\n !.\npn_chars_base(C) :-\n 0x370 =< C,\n C =< 0x37D,\n !.\npn_chars_base(C) :-\n 0x37F =< C,\n C =< 0x1FFF,\n !.\npn_chars_base(C) :-\n 0x200C =< C,\n C =< 0x200D,\n !.\npn_chars_base(C) :-\n 0x2070 =< C,\n C =< 0x218F,\n !.\npn_chars_base(C) :-\n 0x2C00 =< C,\n C =< 0x2FEF,\n !.\npn_chars_base(C) :-\n 0x3001 =< C,\n C =< 0xD7FF,\n !.\npn_chars_base(C) :-\n 0xF900 =< C,\n C =< 0xFDCF,\n !.\npn_chars_base(C) :-\n 0xFDF0 =< C,\n C =< 0xFFFD,\n !.\npn_chars_base(C) :-\n 0x10000 =< C,\n C =< 0xEFFFF.\n\npn_chars(C) :-\n code_type(C, csym),\n !.\npn_chars(C) :-\n pn_chars_base(C),\n !.\npn_chars(0'-) :-\n !.\npn_chars(0xB7) :-\n !.\npn_chars(C) :-\n 0x0300 =< C,\n C =< 0x036F,\n !.\npn_chars(C) :-\n 0x203F =< C,\n C =< 0x2040.\n\nlocal_name(0'\\\\, In, C, Atom) :-\n !,\n get_code(In, C0),\n reserved_char_escapes(C0),\n get_code(In, C1),\n local_name_chars(C1, In, C, T),\n atom_codes(Atom, [C0|T]).\nlocal_name(0'%, In, C, Atom) :-\n !,\n get_code(In, C0),\n code_type(C0, xdigit(_)),\n get_code(In, C1),\n code_type(C1, xdigit(_)),\n get_code(In, C2),\n local_name_chars(C2, In, C, T),\n atom_codes(Atom, [0'%, C0, C1|T]).\nlocal_name(C0, In, C, Atom) :-\n local_name_start_char(C0),\n get_code(In, C1),\n local_name_chars(C1, In, C, T),\n atom_codes(Atom, [C0|T]).\n\nlocal_name_chars(0'\\\\, In, C, [C0|T]) :-\n !,\n get_code(In, C0),\n reserved_char_escapes(C0),\n get_code(In, C1),\n local_name_chars(C1, In, C, T).\nlocal_name_chars(0'%, In, C, [0'%, C0, C1|T]) :-\n !,\n get_code(In, C0),\n code_type(C0, xdigit(_)),\n get_code(In, C1),\n code_type(C1, xdigit(_)),\n get_code(In, C2),\n local_name_chars(C2, In, C, T).\nlocal_name_chars(0'., In, C, [0'.|T]) :-\n peek_code(In, C1),\n ( local_name_char(C1)\n ; C1 = 0'.\n ),\n !,\n get_code(In, C1),\n local_name_chars(C1, In, C, T).\nlocal_name_chars(C0, In, C, [C0|T]) :-\n local_name_char(C0),\n !,\n get_code(In, C1),\n local_name_chars(C1, In, C, T).\nlocal_name_chars(C, _, C, []).\n\nlocal_name_start_char(C) :-\n name_start_char(C),\n !.\nlocal_name_start_char(0':).\nlocal_name_start_char(0'%).\nlocal_name_start_char(0'\\\\).\n\nlocal_name_char(C) :-\n pn_chars(C),\n !.\nlocal_name_char(0':).\nlocal_name_char(0'%).\nlocal_name_char(0'\\\\).\n\nreserved_char_escapes(0'~).\nreserved_char_escapes(0'.).\nreserved_char_escapes(0'-).\nreserved_char_escapes(0'!).\nreserved_char_escapes(0'$).\nreserved_char_escapes(0'&).\nreserved_char_escapes(0'').\nreserved_char_escapes(0'().\nreserved_char_escapes(0')).\nreserved_char_escapes(0'*).\nreserved_char_escapes(0'+).\nreserved_char_escapes(0',).\nreserved_char_escapes(0';).\nreserved_char_escapes(0'=).\nreserved_char_escapes(0'/).\nreserved_char_escapes(0'?).\nreserved_char_escapes(0'#).\nreserved_char_escapes(0'@).\nreserved_char_escapes(0'%).\nreserved_char_escapes(0'_).\n\npunctuation(0'(, '(').\npunctuation(0'), ')').\npunctuation(0'[, '[').\npunctuation(0'], ']').\npunctuation(0',, ',').\npunctuation(0':, ':').\npunctuation(0';, ';').\npunctuation(0'{, '{').\npunctuation(0'}, '}').\npunctuation(0'?, '?').\npunctuation(0'!, '!').\npunctuation(0'^, '^').\npunctuation(0'=, '=').\npunctuation(0'<, '<').\npunctuation(0'>, '>').\npunctuation(0'$, '$').\n\nskip_line(-1, _, -1) :-\n !.\nskip_line(0xA, In, C) :-\n !,\n cnt(line_number),\n get_code(In, C).\nskip_line(0xD, In, C) :-\n !,\n get_code(In, C).\nskip_line(_, In, C) :-\n get_code(In, C1),\n skip_line(C1, In, C).\n\nwhite_space(0x9).\nwhite_space(0xA) :-\n cnt(line_number).\nwhite_space(0xD).\nwhite_space(0x20).\n\n%\n% Reasoning output\n%\n\nw0([]) :-\n !.\nw0(['--image', _|A]) :-\n !,\n w0(A).\nw0([A|B]) :-\n ( \\+sub_atom(A, 1, _, _, '\"'),\n sub_atom(A, _, 1, _, ' '),\n \\+sub_atom(A, _, _, 1, '\"')\n -> format(' \"~w\"', [A])\n ; format(' ~w', [A])\n ),\n w0(B).\n\nw1([]) :-\n !.\nw1([A|B]) :-\n ( \\+sub_atom(A, 1, _, _, '\"'),\n sub_atom(A, _, 1, _, ' '),\n \\+sub_atom(A, _, _, 1, '\"')\n -> format(' \"~w\"', [A])\n ; format(' ~w', [A])\n ),\n w1(B).\n\nwh :-\n ( keep_skolem(_)\n -> nb_getval(var_ns, Sns),\n put_pfx('var', Sns)\n ; true\n ),\n ( flag('no-qnames')\n -> true\n ; nb_setval(wpfx, false),\n forall(\n ( pfx(A, B),\n \\+wpfx(A)\n ),\n ( format('@prefix ~w ~w.~n',[A,B]),\n assertz(wpfx(A)),\n nb_setval(wpfx, true)\n )\n ),\n ( \\+flag('pass-only-new'),\n nb_getval(wpfx, true)\n -> nl\n ; true\n )\n ).\n\nw3 :-\n flag(blogic),\n flag(n3p),\n ( answer(B1, B2, B3),\n relabel([B1, B2, B3], [C1, C2, C3]),\n djiti_answer(answer(C), answer(C1, C2, C3)),\n indent,\n writeq(C),\n ws(C),\n write('.'),\n nl,\n cnt(output_statements),\n fail\n ; nl\n ).\nw3 :-\n wh,\n nb_setval(fdepth, 0),\n nb_setval(pdepth, 0),\n nb_setval(cdepth, 0),\n flag(nope),\n !,\n ( query(Q, A),\n ( Q = \\+(R)\n -> \\+catch(call(R), _, fail)\n ; catch(call(Q), _, fail)\n ),\n nb_getval(wn, W),\n labelvars(A, W, N, some),\n nb_setval(wn, N),\n relabel(A, B),\n indent,\n wt(B),\n ws(B),\n write('.'),\n nl,\n ( A = (_, _),\n conj_list(A, L)\n -> length(L, I),\n cnt(output_statements, I)\n ; cnt(output_statements)\n ),\n fail\n ; true\n ),\n ( answer(B1, B2, B3),\n relabel([B1, B2, B3], [C1, C2, C3]),\n djiti_answer(answer(C), answer(C1, C2, C3)),\n indent,\n wt(C),\n ws(C),\n write('.'),\n nl,\n cnt(output_statements),\n fail\n ; nl\n ).\nw3 :-\n ( prfstep(answer(_, _, _), _, _, _, _, _, _),\n !,\n nb_setval(empty_gives, false),\n indent,\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'proof', '>'], Sk),\n wp(Sk),\n write(' '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Proof>'),\n write(', '),\n wp('<http://www.w3.org/2000/10/swap/reason#Conjunction>'),\n write(';'),\n indentation(2),\n nl,\n indent,\n ( prfstep(answer(_, _, _), B, Pnd, Cn, R, _, A),\n R =.. [P, S, O1],\n djiti_answer(answer(O), O1),\n Rule =.. [P, S, O],\n djiti_answer(answer(C), Cn),\n nb_setval(empty_gives, C),\n \\+got_wi(A, B, Pnd, C, Rule),\n assertz(got_wi(A, B, Pnd, C, Rule)),\n wp('<http://www.w3.org/2000/10/swap/reason#component>'),\n write(' '),\n wi(A, B, C, Rule),\n write(';'),\n nl,\n indent,\n fail\n ; retractall(got_wi(_, _, _, _, _))\n ),\n wp('<http://www.w3.org/2000/10/swap/reason#gives>'),\n ( nb_getval(empty_gives, true)\n -> write(' true.')\n ; write(' {'),\n indentation(2),\n ( prfstep(answer(B1, B2, B3), _, _, _, _, _, _),\n relabel([B1, B2, B3], [C1, C2, C3]),\n djiti_answer(answer(C), answer(C1, C2, C3)),\n nl,\n indent,\n getvars(C, D),\n ( C = '<http://www.w3.org/2000/10/swap/log#implies>'(_, _)\n -> Q = allv\n ; Q = some\n ),\n wq(D, Q),\n wt(C),\n ws(C),\n write('.'),\n cnt(output_statements),\n fail\n ; true\n ),\n indentation(-2),\n nl,\n indent,\n write('}.')\n ),\n indentation(-2),\n nl,\n nl\n ; true\n ),\n ( nb_getval(lemma_count, Lco),\n nb_getval(lemma_cursor, Lcu),\n Lcu < Lco\n -> repeat,\n cnt(lemma_cursor),\n nb_getval(lemma_cursor, Cursor),\n lemma(Cursor, Ai, Bi, Ci, _, Di),\n indent,\n wj(Cursor, Ai, Bi, Ci, Di),\n nl,\n nl,\n nb_getval(lemma_count, Cnt),\n Cursor = Cnt,\n !\n ; true\n ).\n\nwi('<>', _, rule(_, _, A), _) :- % wi(Source, Premise, Conclusion, Rule)\n !,\n write('[ '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Fact>'),\n write('; '),\n wp('<http://www.w3.org/2000/10/swap/reason#gives>'),\n write(' '),\n wg(A),\n write(']').\nwi(A, B, C, Rule) :-\n term_index(B-C, Ind),\n ( lemma(Cnt, A, B, C, Ind, Rule)\n -> true\n ; cnt(lemma_count),\n nb_getval(lemma_count, Cnt),\n assertz(lemma(Cnt, A, B, C, Ind, Rule))\n ),\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'lemma', Cnt, '>'], Sk),\n wp(Sk).\n\nwj(Cnt, A, true, C, Rule) :- % wj(Count, Source, Premise, Conclusion, Rule)\n var(Rule),\n C \\= '<http://www.w3.org/2000/10/swap/log#implies>'(_, _),\n !,\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'lemma', Cnt, '>'], Sk),\n wp(Sk),\n write(' '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Extraction>'),\n writeln(';'),\n indentation(2),\n indent,\n wp('<http://www.w3.org/2000/10/swap/reason#gives>'),\n ( C = true\n -> write(' true;')\n ; write(' {'),\n nl,\n indentation(2),\n indent,\n ( C = rule(PVars, EVars, Rule)\n -> wq(PVars, allv),\n wq(EVars, some),\n wt(Rule)\n ; labelvars([A, C], 0, _, avar),\n getvars(C, D),\n wq(D, some),\n wt(C)\n ),\n ws(C),\n write('.'),\n nl,\n indentation(-2),\n indent,\n write('};')\n ),\n nl,\n indent,\n wp('<http://www.w3.org/2000/10/swap/reason#because>'),\n write(' [ '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Parsing>'),\n write('; '),\n wp('<http://www.w3.org/2000/10/swap/reason#source>'),\n write(' '),\n ( C = rule(_, _, Rl),\n Rl =.. [P, S, O],\n '<http://www.w3.org/2000/10/swap/reason#source>'(triple(S, P, O), Src)\n -> wt(Src)\n ; ( C =.. [P, S, O],\n '<http://www.w3.org/2000/10/swap/reason#source>'(triple(S, P, O), Src)\n -> wt(Src)\n ; wt(A)\n )\n ),\n write('].'),\n indentation(-2).\nwj(Cnt, A, B, C, Rule) :-\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'lemma', Cnt, '>'], Sk),\n wp(Sk),\n write(' '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Inference>'),\n writeln(';'),\n indentation(2),\n indent,\n wp('<http://www.w3.org/2000/10/swap/reason#gives>'),\n ( C = true\n -> write(' true;')\n ; write(' {'),\n nl,\n Rule = '<http://www.w3.org/2000/10/swap/log#implies>'(Prem, Conc),\n unifiable(Prem, B, Bs),\n ( unifiable(Conc, C, Cs)\n -> true\n ; Cs = []\n ),\n append(Bs, Cs, Ds),\n sort(Ds, Bindings),\n term_variables(Prem, PVars),\n term_variables(Conc, CVars),\n nb_getval(wn, W),\n labelvars([A, B, C], W, N, some),\n nb_setval(wn, N),\n labelvars([Rule, PVars, CVars], 0, _, avar),\n findall(V,\n ( member(V, CVars),\n \\+member(V, PVars)\n ),\n EVars\n ),\n getvars(C, D),\n ( C = '<http://www.w3.org/2000/10/swap/log#implies>'(_, _)\n -> Q = allv\n ; Q = some\n ),\n indentation(2),\n indent,\n wq(D, Q),\n wt(C),\n ws(C),\n write('.'),\n nl,\n indentation(-2),\n indent,\n write('};')\n ),\n nl,\n indent,\n wp('<http://www.w3.org/2000/10/swap/reason#evidence>'),\n write(' ('),\n indentation(2),\n wr(B),\n indentation(-2),\n nl,\n indent,\n write(');'),\n retractall(got_wi(_, _, _, _, _)),\n nl,\n indent,\n wb(Bindings),\n wp('<http://www.w3.org/2000/10/swap/reason#rule>'),\n write(' '),\n wi(A, true, rule(PVars, EVars, Rule), _),\n write('.'),\n indentation(-2).\n\nwr(exopred(P, S, O)) :-\n atom(P),\n !,\n U =.. [P, S, O],\n wr(U).\nwr((X, Y)) :-\n !,\n wr(X),\n wr(Y).\nwr(Z) :-\n prfstep(Z, Y, _, Q, Rule, _, X),\n !,\n nl,\n indent,\n wi(X, Y, Q, Rule).\nwr(Y) :-\n nl,\n indent,\n write('[ '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Fact>'),\n write('; '),\n wp('<http://www.w3.org/2000/10/swap/reason#gives>'),\n write(' '),\n ( Y = true\n -> wt(Y)\n ; write('{'),\n labelvars(Y, 0, _, avar),\n getvars(Y, Z),\n wq(Z, some),\n X = Y,\n wt(X),\n write('}')\n ),\n write(']').\n\nwt(X) :-\n var(X),\n !,\n write('?'),\n write(X).\nwt(X) :-\n functor(X, _, A),\n ( A = 0,\n !,\n wt0(X)\n ; A = 1,\n !,\n wt1(X)\n ; A = 2,\n !,\n wt2(X)\n ; wtn(X)\n ).\n\nwt0(!) :-\n !,\n write('(\"!\") '),\n wp('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'),\n write(' true').\nwt0(fail) :-\n !,\n write('(\"fail\") '),\n wp('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'),\n write(' true').\nwt0([]) :-\n !,\n write('()').\nwt0(X) :-\n number(X),\n !,\n ( flag('no-numerals')\n -> dtlit([U, V], X),\n dtlit([U, V], W),\n wt(W)\n ; write(X)\n ).\nwt0(X) :-\n atom(X),\n atom_concat(some, Y, X),\n !,\n ( \\+flag('no-qvars')\n -> ( rule_uvar(L),\n ( ncllit\n -> ( memberchk(X, L)\n -> true\n ; retract(rule_uvar(L)),\n assertz(rule_uvar([X|L]))\n )\n ; memberchk(X, L)\n )\n -> write('?U_')\n ; write('_:sk_')\n ),\n write(Y)\n ; atomic_list_concat(['<http://eyereasoner.github.io/var#some_', Y, '>'], Z),\n wt0(Z)\n ).\nwt0(X) :-\n atom(X),\n atom_concat(allv, Y, X),\n !,\n ( \\+flag('no-qvars'),\n \\+flag('pass-all-ground')\n -> write('?U_'),\n write(Y)\n ; atomic_list_concat(['<http://eyereasoner.github.io/var#all_', Y, '>'], Z),\n wt0(Z)\n ).\nwt0(X) :-\n atom(X),\n atom_concat(avar, Y, X),\n !,\n atomic_list_concat(['<http://eyereasoner.github.io/var#x_', Y, '>'], Z),\n wt0(Z).\nwt0(X) :-\n flag(nope),\n \\+flag('pass-all-ground'),\n \\+keep_skolem(X),\n nb_getval(var_ns, Sns),\n atom(X),\n sub_atom(X, 1, I, _, Sns),\n J is I+1,\n sub_atom(X, J, _, 1, Y),\n ( getlist(X, M)\n -> wt(M)\n ; ( rule_uvar(L),\n ( ncllit\n -> ( memberchk(Y, L)\n -> true\n ; retract(rule_uvar(L)),\n assertz(rule_uvar([Y|L]))\n )\n ; memberchk(Y, L)\n )\n -> ( ( sub_atom(Y, 0, 2, _, 'e_')\n ; sub_atom(Y, 0, 3, _, 'bn_')\n )\n -> write('_:')\n ; sub_atom(Y, 0, 2, _, Z),\n memberchk(Z, ['x_', 't_']),\n write('?')\n )\n ; ( \\+flag('no-qvars')\n -> true\n ; flag('quantify', Prefix),\n sub_atom(X, 1, _, _, Prefix)\n ),\n write('_:')\n ),\n write(Y),\n ( sub_atom(Y, 0, 2, _, 'x_')\n -> write('_'),\n nb_getval(rn, N),\n write(N)\n ; true\n )\n ),\n !.\nwt0(X) :-\n flag('quantify', Prefix),\n flag(nope),\n atom(X),\n sub_atom(X, 1, _, _, Prefix),\n !,\n ( getlist(X, M)\n -> wt(M)\n ; '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(Y, ['quantify', Prefix, X]),\n wt0(Y)\n ).\nwt0(X) :-\n ( wtcache(X, W)\n -> true\n ; ( \\+flag('no-qnames'),\n atom(X),\n ( sub_atom(X, I, 1, J, '#')\n -> J > 1,\n sub_atom(X, 0, I, _, C),\n atom_concat(C, '#>', D)\n ; ( sub_atom_last(X, I, 1, J, '/')\n -> J > 1,\n sub_atom(X, 0, I, _, C),\n atom_concat(C, '/>', D)\n ; J = 1,\n D = X\n )\n ),\n pfx(E, D),\n K is J-1,\n sub_atom(X, _, K, 1, F)\n -> atom_concat(E, F, W),\n assertz(wtcache(X, W))\n ; ( \\+flag(strings),\n atom(X),\n \\+ (sub_atom(X, 0, 1, _, '<'), sub_atom(X, _, 1, 0, '>')),\n X \\= true,\n X \\= false\n -> W = literal(X, type('<http://www.w3.org/2001/XMLSchema#string>'))\n ; W = X\n )\n )\n ),\n ( W = literal(X, type('<http://www.w3.org/2001/XMLSchema#string>'))\n -> wt2(W)\n ; ( current_prolog_flag(windows, true)\n -> atom_codes(W, U),\n escape_unicode(U, V),\n atom_codes(Z, V)\n ; Z = W\n ),\n ( atom(Z)\n -> write(Z)\n ; '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(A, [blob, Z]),\n wt(A)\n )\n ).\n\nwt1(set(X)) :-\n !,\n write('($'),\n wl(X),\n write(' $)').\nwt1('$VAR'(X)) :-\n !,\n write('?V'),\n write(X).\nwt1(X) :-\n X =.. [B|C],\n ( atom(B),\n \\+ (sub_atom(B, 0, 1, _, '<'), sub_atom(B, _, 1, 0, '>'))\n -> write('\"'),\n writeq(X),\n write('\"')\n ; wt(C),\n write(' '),\n wp(B),\n write(' true')\n ).\n\nwt2((X, Y)) :-\n !,\n ( atomic(X),\n X \\= '!'\n -> wt2([X, Y]),\n write(' '),\n wt0('<http://eulersharp.sourceforge.net/2003/03swap/prolog#conjunction>'),\n write(' true')\n ; wt(X),\n ws(X),\n write('.'),\n ( ( flag(strings)\n ; flag(nope)\n )\n -> write(' ')\n ; nl,\n indent\n ),\n wt(Y)\n ).\nwt2([X|Y]) :-\n !,\n ( \\+last_tail([X|Y], [])\n -> write('[ '),\n wt0('<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>'),\n write(' '),\n wg(X),\n write('; '),\n wt0('<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'),\n write(' '),\n wt(Y),\n write(']')\n ; write('('),\n wg(X),\n wl(Y),\n write(')')\n ).\nwt2(literal(X, lang(Y))) :-\n !,\n write('\"'),\n ( current_prolog_flag(windows, true)\n -> atom_codes(X, U),\n escape_unicode(U, V),\n atom_codes(Z, V)\n ; Z = X\n ),\n write(Z),\n write('\"@'),\n write(Y).\nwt2(literal(X, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n !,\n ( sub_atom(X, _, 2, _, '\\\\n')\n -> write('\"\"\"'),\n atom_codes(X, C),\n escape_string(D, C),\n atom_codes(Y, D),\n ( current_prolog_flag(windows, true)\n -> atom_codes(Y, U),\n escape_unicode(U, V),\n atom_codes(Z, V)\n ; Z = Y\n ),\n write(Z),\n write('\"\"\"')\n ; write('\"'),\n ( current_prolog_flag(windows, true)\n -> atom_codes(X, U),\n escape_unicode(U, V),\n atom_codes(Z, V)\n ; Z = X\n ),\n write(Z),\n write('\"')\n ).\nwt2(literal(X, type(Y))) :-\n !,\n write('\"'),\n ( current_prolog_flag(windows, true)\n -> atom_codes(X, U),\n escape_unicode(U, V),\n atom_codes(Z, V)\n ; Z = X\n ),\n write(Z),\n write('\"^^'),\n wt(Y).\nwt2(rdiv(X, Y)) :-\n number_codes(Y, [0'1|Z]),\n lzero(Z, Z),\n !,\n ( Z = []\n -> F = '~d.0'\n ; length(Z, N),\n number_codes(X, U),\n ( length(U, N)\n -> F = '0.~d'\n ; atomic_list_concat(['~', N, 'd'], F)\n )\n ),\n ( flag('no-numerals')\n -> write('\"')\n ; true\n ),\n format(F, [X]),\n ( flag('no-numerals')\n -> write('\"^^'),\n wt0('<http://www.w3.org/2001/XMLSchema#decimal>')\n ; true\n ).\nwt2(rdiv(X, Y)) :-\n !,\n ( flag('no-numerals')\n -> write('\"')\n ; true\n ),\n format('~g', [rdiv(X, Y)]),\n ( flag('no-numerals')\n -> write('\"^^'),\n wt0('<http://www.w3.org/2001/XMLSchema#decimal>')\n ; true\n ).\nwt2('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#biconditional>'([X|Y], Z)) :-\n flag(nope),\n !,\n '<http://www.w3.org/2000/10/swap/log#conjunction>'(Y, U),\n write('{'),\n wt(U),\n write('. _: '),\n wp('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#true>'),\n write(' '),\n wt(Z),\n write('} '),\n wp('<http://www.w3.org/2000/10/swap/log#implies>'),\n write(' {'),\n wt(X),\n write('}').\nwt2('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#conditional>'([X|Y], Z)) :-\n flag(nope),\n !,\n '<http://www.w3.org/2000/10/swap/log#conjunction>'(Y, U),\n write('{'),\n wt(U),\n write('. _: '),\n wp('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#true>'),\n write(' '),\n wt(Z),\n write('} '),\n wp('<http://www.w3.org/2000/10/swap/log#implies>'),\n write(' {'),\n wt(X),\n write('}').\nwt2('<http://www.w3.org/2000/10/swap/log#implies>'(X, Y)) :-\n ( flag(nope)\n -> U = X\n ; ( X = when(A, B)\n -> conj_append(B, istep(_, _, _, _), C),\n U = when(A, C)\n ; conj_append(X, istep(_, _, _, _), U)\n )\n ),\n ( flag('rule-histogram')\n -> ( U = when(D, E)\n -> conj_append(E, pstep(_), F),\n Z = when(D, F)\n ; conj_append(U, pstep(_), Z)\n )\n ; Z = U\n ),\n ( rule_uvar(R)\n -> true\n ; R = [],\n cnt(rn)\n ),\n ( nb_getval(pdepth, 0),\n nb_getval(cdepth, 0)\n -> assertz(rule_uvar(R))\n ; true\n ),\n ( catch(clause(Y, Z), _, fail)\n -> ( nb_getval(fdepth, 0)\n -> assertz(ncllit)\n ; true\n ),\n wg(Y),\n write(' <= '),\n wg(X),\n ( nb_getval(fdepth, 0)\n -> retract(ncllit)\n ; true\n )\n ; ( clause('<http://www.w3.org/2000/10/swap/log#implies>'(X, Y, _, _, _, _), true)\n -> wg(X),\n write(' => '),\n wg(Y)\n ; ( nb_getval(fdepth, 0)\n -> assertz(ncllit)\n ; true\n ),\n ( \\+atom(X)\n -> nb_getval(pdepth, PD),\n PD1 is PD+1,\n nb_setval(pdepth, PD1)\n ; true\n ),\n wg(X),\n ( \\+atom(X)\n -> nb_setval(pdepth, PD)\n ; true\n ),\n ( nb_getval(fdepth, 0)\n -> retract(ncllit)\n ; true\n ),\n write(' => '),\n ( \\+atom(Y)\n -> nb_getval(cdepth, CD),\n CD1 is CD+1,\n nb_setval(cdepth, CD1)\n ; true\n ),\n wg(Y),\n ( \\+atom(Y)\n -> nb_setval(cdepth, CD)\n ; true\n )\n )\n ),\n ( nb_getval(pdepth, 0),\n nb_getval(cdepth, 0)\n -> retract(rule_uvar(_))\n ; true\n ),\n !.\nwt2(':-'(X, Y)) :-\n ( rule_uvar(R)\n -> true\n ; R = [],\n cnt(rn)\n ),\n ( nb_getval(fdepth, 0)\n -> assertz(ncllit)\n ; true\n ),\n assertz(rule_uvar(R)),\n ( Y = true\n -> wt(X)\n ; wg(X),\n write(' <= '),\n wg(Y),\n retract(rule_uvar(U)),\n ( U \\= [],\n retract(rule_uvar(V)),\n append(U, V, W)\n -> assertz(rule_uvar(W))\n ; true\n )\n ),\n ( nb_getval(fdepth, 0)\n -> retract(ncllit)\n ; true\n ),\n !.\nwt2(is(O, T)) :-\n !,\n ( number(T),\n T < 0\n -> P = -,\n Q is -T,\n S = [Q]\n ; T =.. [P|S]\n ),\n wg(S),\n write(' '),\n wp(P),\n write(' '),\n wg(O).\nwt2(prolog:X) :-\n !,\n ( X = '\\';\\''\n -> Y = disjunction\n ; prolog_sym(Y, X, _)\n ),\n atomic_list_concat(['<http://eulersharp.sourceforge.net/2003/03swap/prolog#', Y, '>'], Z),\n wt0(Z).\nwt2(X) :-\n X =.. [P, S, O],\n ( atom(P),\n \\+ (sub_atom(P, 0, 1, _, '<'), sub_atom(P, _, 1, 0, '>')),\n \\+sub_atom(P, 0, _, _, avar),\n \\+sub_atom(P, 0, _, _, some)\n -> write('\"'),\n writeq(X),\n write('\"')\n ; wg(S),\n write(' '),\n wp(P),\n write(' '),\n wg(O)\n ).\n\nwtn(exopred(P, S, O)) :-\n !,\n ( atom(P)\n -> X =.. [P, S, O],\n wt2(X)\n ; wg(S),\n write(' '),\n wg(P),\n write(' '),\n wg(O)\n ).\nwtn(triple(S, P, O)) :-\n !,\n write('<<'),\n wg(S),\n write(' '),\n wp(P),\n write(' '),\n wg(O),\n write('>>').\nwtn(X) :-\n X =.. [B|C],\n ( atom(B),\n \\+ (sub_atom(B, 0, 1, _, '<'), sub_atom(B, _, 1, 0, '>'))\n -> write('\"'),\n writeq(X),\n write('\"')\n ; wt(C),\n write(' '),\n wp(B),\n write(' true')\n ).\n\nwg(X) :-\n var(X),\n !,\n write('?'),\n write(X).\nwg(X) :-\n functor(X, F, A),\n ( ( F = exopred,\n !\n ; prolog_sym(_, F, _),\n F \\= true,\n F \\= false,\n F \\= '-',\n F \\= /,\n !\n ; A = 2,\n F \\= '.',\n F \\= '[|]',\n F \\= ':',\n F \\= literal,\n F \\= rdiv,\n ( sub_atom(F, 0, 1, _, '<'),\n sub_atom(F, _, 1, 0, '>')\n ; F = ':-'\n )\n )\n -> write('{'),\n indentation(1),\n nb_getval(fdepth, D),\n E is D+1,\n nb_setval(fdepth, E),\n wt(X),\n nb_setval(fdepth, D),\n indentation(-1),\n write('}')\n ; wt(X)\n ).\n\nwp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>') :-\n \\+flag('no-qnames'),\n !,\n write('a').\nwp('<http://www.w3.org/2000/10/swap/log#implies>') :-\n \\+flag('no-qnames'),\n !,\n write('=>').\nwp(':-') :-\n \\+flag('no-qnames'),\n !,\n write('<=').\nwp(X) :-\n ( prolog_sym(Y, X, _),\n X \\= true,\n X \\= false\n -> atomic_list_concat(['<http://eulersharp.sourceforge.net/2003/03swap/prolog#', Y, '>'], Z),\n wt(Z)\n ; wg(X)\n ).\n\nwk([]) :-\n !.\nwk([X|Y]) :-\n write(', '),\n wt(X),\n wk(Y).\n\nwl([]) :-\n !.\nwl([X|Y]) :-\n write(' '),\n wg(X),\n wl(Y).\n\nwq([],_) :-\n !.\nwq([X|Y],allv) :-\n !,\n write('@forAll '),\n wt(X),\n wk(Y),\n write('. ').\nwq([X|Y],some) :-\n ( \\+flag('no-qvars')\n -> write('@forSome '),\n wt(X),\n wk(Y),\n write('. ')\n ; true\n ).\n\nwb([]) :-\n !.\nwb([X = Y|Z]) :-\n wp('<http://www.w3.org/2000/10/swap/reason#binding>'),\n write(' [ '),\n wp('<http://www.w3.org/2000/10/swap/reason#variable>'),\n write(' '),\n wv(X),\n write('; '),\n wp('<http://www.w3.org/2000/10/swap/reason#boundTo>'),\n write(' '),\n wv(Y),\n write('];'),\n nl,\n indent,\n wb(Z).\n\nwv(X) :-\n atom(X),\n atom_concat(avar, Y, X),\n !,\n write('[ '),\n wp('<http://www.w3.org/2004/06/rei#uri>'),\n write(' \"http://eyereasoner.github.io/var#x_'),\n write(Y),\n write('\"]').\nwv(X) :-\n atom(X),\n atom_concat(some, Y, X),\n !,\n write('[ '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Existential>'),\n write('; '),\n wp('<http://www.w3.org/2004/06/rei#nodeId>'),\n write(' \"_:sk_'),\n write(Y),\n write('\"]').\nwv(X) :-\n atom(X),\n nb_getval(var_ns, Sns),\n sub_atom(X, 1, I, _, Sns),\n !,\n write('[ '),\n wp('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'),\n write(' '),\n wp('<http://www.w3.org/2000/10/swap/reason#Existential>'),\n write('; '),\n wp('<http://www.w3.org/2004/06/rei#nodeId>'),\n write(' \"'),\n write(Sns),\n J is I+1,\n sub_atom(X, J, _, 1, Q),\n write(Q),\n write('\"]').\nwv(X) :-\n atom(X),\n sub_atom(X, 1, _, 1, U),\n atomic_list_concat(['<', U, '>'], X),\n !,\n write('[ '),\n wp('<http://www.w3.org/2004/06/rei#uri>'),\n write(' \"'),\n write(U),\n write('\"]').\nwv(X) :-\n wg(X).\n\nws((X, Y)) :-\n !,\n conj_list((X, Y), Z),\n last(Z, U),\n ws(U).\nws(X) :-\n X =.. Y,\n last(Y, Z),\n ( \\+number(Z),\n Z \\= rdiv(_, _)\n -> true\n ; write(' ')\n ).\n\nwst :-\n findall([Key, Str],\n ( '<http://www.w3.org/2000/10/swap/log#outputString>'(Key, Str)\n ; answer(A1, A2, A3),\n djiti_answer(answer('<http://www.w3.org/2000/10/swap/log#outputString>'(Key, Str)), answer(A1, A2, A3))\n ),\n KS\n ),\n sort(KS, KT),\n forall(\n ( member([_, MT], KT),\n getcodes(MT, LT)\n ),\n ( escape_string(NT, LT),\n atom_codes(ST, NT),\n wt(ST)\n )\n ),\n ( catch(nb_getval(csv_header, Header), _, Header = []),\n wct(Header, Header),\n length(Header, Headerl),\n query(Where, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#csvTuple>'(_, Select)),\n catch(call(Where), _, fail),\n write('\\r\\n'),\n wct(Select, Header),\n cnt(output_statements, Headerl),\n cnt(answer_count),\n nb_getval(answer_count, AnswerCount),\n ( flag('limited-answer', AnswerLimit),\n AnswerCount >= AnswerLimit\n -> true\n ; fail\n )\n ; true\n ).\n\nwct([], []) :-\n !.\nwct([A], [C]) :-\n !,\n wcf(A, C).\nwct([A|B], [C|D]) :-\n wcf(A, C),\n ( flag('csv-separator', S)\n -> true\n ; S = ','\n ),\n write(S),\n wct(B, D).\n\nwcf(A, _) :-\n var(A),\n !.\nwcf(rdiv(X, Y), _) :-\n number_codes(Y, [0'1|Z]),\n lzero(Z, Z),\n !,\n ( Z = []\n -> F = '~d.0'\n ; length(Z, N),\n number_codes(X, U),\n ( length(U, N)\n -> F = '0.~d'\n ; atomic_list_concat(['~', N, 'd'], F)\n )\n ),\n format(F, [X]).\nwcf(literal(A, B), _) :-\n !,\n atom_codes(A, C),\n subst([[[0'\\\\, 0'\"], [0'\", 0'\"]]], C, E),\n atom_codes(F, E),\n ( B \\= type('<http://www.w3.org/2001/XMLSchema#dateTime>'),\n B \\= type('<http://www.w3.org/2001/XMLSchema#date>'),\n B \\= type('<http://www.w3.org/2001/XMLSchema#time>'),\n B \\= type('<http://www.w3.org/2001/XMLSchema#duration>'),\n B \\= type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'),\n B \\= type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')\n -> write('\"'),\n write(F),\n write('\"')\n ; write(F)\n ).\nwcf(A, _) :-\n atom(A),\n nb_getval(var_ns, Sns),\n sub_atom(A, 1, I, _, Sns),\n !,\n J is I+1,\n sub_atom(A, J, _, 1, B),\n write('_:'),\n write(B).\nwcf(A, _) :-\n atom(A),\n flag('quantify', Prefix),\n sub_atom(A, 1, _, _, Prefix),\n !,\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(B, ['quantify', Prefix, A]),\n wt0(B).\nwcf(A, B) :-\n atom(A),\n relabel(A, C),\n sub_atom(C, 0, 1, _, '<'),\n sub_atom(C, _, 1, 0, '>'),\n !,\n sub_atom(C, 1, _, 1, D),\n ( sub_atom(B, _, 2, 0, 'ID')\n -> ( flag('hmac-key', Key)\n -> hmac_sha(Key, D, E, [algorithm(sha1)])\n ; sha_hash(D, E, [algorithm(sha1)])\n ),\n atom_codes(F, E),\n base64xml(F, G),\n write(G)\n ; write(D)\n ).\nwcf(A, _) :-\n atom(A),\n sub_atom(A, 0, 1, _, '_'),\n !,\n sub_atom(A, 1, _, 0, B),\n write(B).\nwcf(A, _) :-\n with_output_to(atom(B), wg(A)),\n write(B).\n\nindent:-\n nb_getval(indentation, A),\n tab(A).\n\nindentation(C) :-\n nb_getval(indentation, A),\n B is A+C,\n nb_setval(indentation, B).\n\n\n% ----------------------------\n% EAM (Euler Abstract Machine)\n% ----------------------------\n%\n% In a nutshell:\n%\n% 1/ Select rule P => C\n% 2/ Prove P & NOT(C) (backward chaining) and if it fails backtrack to 1/\n% 3/ If P & NOT(C) assert C (forward chaining) and remove brake\n% 4/ If C = answer(A) and tactic limited-answer stop, else backtrack to 2/\n% 5/ If brake or tactic linear-select stop, else start again at 1/\n%\n\neam(Span) :-\n ( cnt(tr),\n ( flag(debug)\n -> format(user_error, 'eam/1 entering span ~w~n', [Span]),\n flush_output(user_error)\n ; true\n ),\n ( flag('max-inferences', MaxInf),\n statistics(inferences, Inf),\n Inf > MaxInf\n -> throw(max_inferences_exceeded(MaxInf))\n ; true\n ),\n implies(Prem, Conc, Src),\n ignore(Prem = true),\n ( flag(nope),\n \\+flag('rule-histogram')\n -> true\n ; copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(Prem, Conc), Rule)\n ),\n ( flag(debug)\n -> format(user_error, '. eam/1 selecting rule ~q~n', [implies(Prem, Conc, Src)]),\n flush_output(user_error)\n ; true\n ),\n ( flag('no-ucall')\n -> catch(call_residue_vars(call(Prem), []), Exc,\n ( Exc = error(existence_error(procedure, _), _)\n -> fail\n ; throw(Exc)\n )\n )\n ; catch(call_residue_vars(ucall(Prem), []), Exc,\n ( Exc = error(existence_error(procedure, _), _)\n -> fail\n ; throw(Exc)\n )\n )\n ),\n ( ( Conc = false\n ; Conc = answer(false, void, void)\n )\n -> with_output_to(atom(PN3), wt('<http://www.w3.org/2000/10/swap/log#implies>'(Prem, false))),\n ( flag('ignore-inference-fuse')\n -> format(user_error, '** ERROR ** eam ** ~w~n', [inference_fuse(PN3)]),\n fail\n ; throw(inference_fuse(PN3))\n )\n ; true\n ),\n \\+atom(Conc),\n ( flag('rule-histogram'),\n copy_term_nat(Rule, RuleL)\n -> lookup(RTP, tp, RuleL),\n catch(cnt(RTP), _, nb_setval(RTP, 0))\n ; true\n ),\n cnt(tp),\n djiti_conc(Conc, Concd),\n ( Concd = ':-'(Head, Body)\n -> \\+clause(Head, Body)\n ; ( Concd = '<http://www.w3.org/2000/10/swap/log#implies>'(_, _)\n -> copy_term_nat(Concd, Concc),\n labelvars(Concc, 0, _, avar),\n \\+cc(Concc),\n assertz(cc(Concc))\n ; ( flag('no-ucall')\n -> \\+catch(call(Concd), _, fail)\n ; \\+catch(ucall(Concd), _, fail)\n )\n )\n ),\n ( flag('rule-histogram')\n -> lookup(RTC, tc, RuleL),\n catch(cnt(RTC), _, nb_setval(RTC, 0))\n ; true\n ),\n ( Concd = (_, _),\n conj_list(Concd, Cl)\n -> length(Cl, Ci),\n cnt(tc, Ci)\n ; cnt(tc)\n ),\n ( Concd \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(_, _),\n Concd \\= ':-'(_, _)\n -> nb_getval(wn, W),\n labelvars(Prem-Concd, W, N), % failing when Prem contains attributed variables\n nb_setval(wn, N)\n ; true\n ),\n ( flag(debug)\n -> format(user_error, '... eam/1 assert step ~q~n', [Concd]),\n flush_output(user_error)\n ; true\n ),\n conj_list(Concd, La),\n couple(La, La, Lc),\n findall([D, F],\n ( member([D, D], Lc),\n unify(D, F),\n ( F = '<http://www.w3.org/2000/10/swap/log#implies>'(_, _)\n -> true\n ; catch(\\+F, _, true)\n )\n ),\n Ld\n ),\n couple(Ls, Le, Ld),\n conj_list(Concs, Ls),\n conj_list(Conce, Le),\n astep(Src, Prem, Concd, Conce, Rule),\n ( ( Concs = answer(_, _, _)\n ; Concs = (answer(_, _, _), _)\n )\n -> cnt(answer_count)\n ; true\n ),\n nb_getval(answer_count, AnswerCount),\n ( flag('limited-answer', AnswerLimit),\n AnswerCount >= AnswerLimit\n -> ( flag(strings)\n -> true\n ; w3\n )\n ; retract(brake),\n fail\n )\n ; ( brake\n ; flag(tactic, 'linear-select')\n ),\n ( S is Span+1,\n ( \\+span(S)\n -> assertz(span(S))\n ; true\n ),\n nb_getval(limit, Limit),\n Span < Limit,\n eam(S)\n ; \\+flag('multi-query'),\n \\+got_models,\n forall(\n modelo(Mz, Mn, Ml),\n retract(model(Mz, Mn, Ml))\n ),\n ( flag('debug-models')\n -> mf(model(_, _, _))\n ; true\n ),\n ( model(Mx, _, _),\n findall(My,\n ( model(Mx, _, My)\n ),\n Mq\n ),\n Mq = [Mh|Mt],\n findall(Me,\n ( member(Me, Mh),\n forall(\n member(Mm, Mt),\n member(Me, Mm)\n ),\n ( \\+Me\n -> djiti_assertz(Me)\n ; true\n )\n ),\n _\n ),\n fail\n ; true\n ),\n assertz(got_models),\n eam(Span)\n ; ( flag(strings)\n -> true\n ; w3\n )\n ; true\n ),\n !\n ; assertz(brake),\n exogen,\n eam(Span)\n ).\n\nastep(A, B, Cd, Cn, Rule) :- % astep(Source, Premise, Conclusion, Conclusion_unique, Rule)\n ( Cn = (Dn, En)\n -> functor(Dn, P, N),\n ( \\+pred(P),\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>',\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>',\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>',\n P \\= '<http://www.w3.org/2000/10/swap/log#implies>',\n P \\= '<http://www.w3.org/2000/10/swap/log#callWithCleanup>',\n N = 2\n -> assertz(pred(P))\n ; true\n ),\n ( Dn \\= '<http://www.w3.org/2000/10/swap/log#implies>'(_, _),\n catch(call(Dn), _, fail)\n -> true\n ; djiti_assertz(Dn),\n ( flag('pass-only-new'),\n Dn \\= answer(_, _, _),\n \\+pass_only_new(Dn)\n -> assertz(pass_only_new(Dn))\n ; true\n ),\n ( flag(nope)\n -> true\n ; ( B = '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(P1, Q1),\n Rule = '<http://www.w3.org/2000/10/swap/log#implies>'(Q6, R6),\n prfstep('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(P1, Q1), Q3, Q4, _,\n '<http://www.w3.org/2000/10/swap/log#implies>'(P6, Q6), forward, A)\n -> assertz(prfstep(Dn, Q3, Q4, Cd, '<http://www.w3.org/2000/10/swap/log#implies>'(P6, R6), forward, A))\n ; term_index(B, Pnd),\n assertz(prfstep(Dn, B, Pnd, Cd, Rule, forward, A))\n )\n )\n ),\n astep(A, B, Cd, En, Rule)\n ; ( Cn = true\n -> true\n ; functor(Cn, P, N),\n ( \\+pred(P),\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>',\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>',\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>',\n P \\= '<http://www.w3.org/2000/10/swap/log#callWithCleanup>',\n P \\= '<http://www.w3.org/2000/10/swap/log#implies>',\n N = 2\n -> assertz(pred(P))\n ; true\n ),\n ( Cn \\= '<http://www.w3.org/2000/10/swap/log#implies>'(_, _),\n catch(call(Cn), _, fail)\n -> true\n ; djiti_assertz(Cn),\n ( flag('pass-only-new'),\n Cn \\= answer(_, _, _),\n \\+pass_only_new(Cn)\n -> assertz(pass_only_new(Cn))\n ; true\n ),\n ( flag(nope)\n -> true\n ; ( B = '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(P1, Q1),\n Rule = '<http://www.w3.org/2000/10/swap/log#implies>'(Q6, R6),\n prfstep('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(P1, Q1), Q3, Q4, _,\n '<http://www.w3.org/2000/10/swap/log#implies>'(P6, Q6), forward, A)\n -> assertz(prfstep(Cn, Q3, Q4, Cd, '<http://www.w3.org/2000/10/swap/log#implies>'(P6, R6), forward, A))\n ; term_index(B, Pnd),\n assertz(prfstep(Cn, B, Pnd, Cd, Rule, forward, A))\n )\n )\n )\n )\n ).\n\nistep(Src, Prem, Conc, Rule) :- % istep(Source, Premise, Conclusion, Rule)\n copy_term_nat(Prem, Prec),\n labelvars(Prec, 0, _),\n term_index(Prec, Pnd),\n ( \\+prfstep(Conc, Prec, Pnd, Conc, Rule, backward, Src)\n -> assertz(prfstep(Conc, Prec, Pnd, Conc, Rule, backward, Src))\n ; true\n ).\n\npstep(Rule) :-\n copy_term_nat(Rule, RuleL),\n lookup(RTC, tc, RuleL),\n catch(cnt(RTC), _, nb_setval(RTC, 0)),\n lookup(RTP, tp, RuleL),\n catch(cnt(RTP), _, nb_setval(RTP, 0)).\n\nhstep(A, B) :-\n ( nonvar(A),\n A = exopred(P, S, O)\n -> pred(P),\n U =.. [P, S, O],\n qstep(U, B)\n ; qstep(A, B)\n ).\n\nqstep(A, B) :-\n prfstep(A, B, _, _, _, _, _).\nqstep(A, true) :-\n ( nonvar(A)\n -> ( A =.. [P, [S1, S2|S3], O]\n -> B =.. [P, S1, S2, S3, O]\n ; ( A =.. [P, S, literal(O1, O2)]\n -> B =.. [P, S, O1, O2]\n ; B = A\n )\n )\n ; pred(P),\n A =.. [P, _, _],\n B = A\n ),\n catch(clause(B, true), _, fail),\n \\+prfstep(A, _, _, _, _, _, _).\n\n%\n% DJITI (Deep Just In Time Indexing)\n%\n\ndjiti_answer(answer((A, B)), (C, D)) :-\n !,\n djiti_answer(answer(A), C),\n djiti_answer(answer(B), D).\ndjiti_answer(answer(A), answer(P, S, O)) :-\n ( nonvar(A)\n ; atom(P),\n S \\= void\n ),\n A =.. [P, S, O],\n !.\ndjiti_answer(answer(exopred(P, S, O)), answer(P, S, O)) :-\n ( var(S)\n ; S \\= void\n ),\n !.\ndjiti_answer(answer(A), answer(A, void, void)) :-\n !.\ndjiti_answer(A, A).\n\ndjiti_conc(':-'(exopred(P, S, O), B), ':-'(A, B)) :-\n !,\n A =.. [P, S, O].\ndjiti_conc(answer((A, B), void, void), (answer(A, void, void), D)) :-\n !,\n djiti_conc(answer(B, void, void), D).\ndjiti_conc(A, A).\n\ndjiti_fact(answer(P, S, O), answer(P, S, O)) :-\n atomic(P),\n !,\n ( P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>',\n P \\= '<http://www.w3.org/2000/10/swap/log#callWithCleanup>',\n \\+pred(P)\n -> assertz(pred(P))\n ; true\n ).\ndjiti_fact(implies(A, B, C), implies(A, B, C)) :-\n nonvar(B),\n conj_list(B, D),\n forall(\n member(E, D),\n ( unify(E, F),\n F =.. [P, _, _],\n ( \\+fpred(P)\n -> assertz(fpred(P))\n ; true\n )\n )\n ),\n !.\ndjiti_fact('<http://www.w3.org/2000/10/swap/log#implies>'(A, B), C) :-\n nonvar(B),\n ( conj_list(B, D)\n -> true\n ; D = B\n ),\n forall(\n member(E, D),\n ( unify(E, F),\n ( F =.. [P, _, _],\n \\+fpred(P)\n -> assertz(fpred(P))\n ; true\n )\n )\n ),\n !,\n ( retwist(A, B, Z)\n -> true\n ; Z = '<>'\n ),\n makevars(implies(A, B, Z), C, zeta).\ndjiti_fact(':-'(A, B), ':-'(C, D)) :-\n !,\n makevars((A, B), (C, E), eta),\n copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(E, C), F),\n ( flag(nope)\n -> D = E\n ; retwist(E, C, G),\n ( E = when(H, I)\n -> conj_append(I, istep(G, E, C, F), J),\n D = when(H, J)\n ; conj_append(E, istep(G, E, C, F), D)\n )\n ).\ndjiti_fact('<http://www.w3.org/2000/10/swap/log#dcg>'(_, literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))), B) :-\n !,\n read_term_from_atom(A, C, []),\n dcg_translate_rule(C, B).\ndjiti_fact('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(A, B), ':-'('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(A, B), true)) :-\n !.\ndjiti_fact(A, A) :-\n ground(A),\n A =.. [P, _, _],\n ( P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>',\n P \\= '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>',\n P \\= '<http://www.w3.org/2000/10/swap/log#callWithCleanup>',\n P \\= query,\n P \\= pfx,\n P \\= flag,\n P \\= semantics,\n \\+pred(P)\n -> assertz(pred(P))\n ; true\n ),\n !.\ndjiti_fact(A, A).\n\ndjiti_assertz(A) :-\n djiti_fact(A, B),\n assertz(B).\n\n%\n% Built-ins\n%\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#avg>'(A, B) :-\n \\+flag(restricted),\n avg(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#becomes>'(A, B) :-\n \\+flag(restricted),\n catch(call(A), _, fail),\n A \\= B,\n unify(A, C),\n conj_list(C, D),\n forall(\n member(E, D),\n ( ( E = '<http://www.w3.org/2000/10/swap/log#implies>'(Prem, Conc)\n -> retract(implies(Prem, Conc, Src)),\n assertz(retwist(Prem, Conc, Src))\n ; ( E = ':-'(Ci, Pi),\n Pi \\= true\n -> ( flag(nope)\n -> Ph = Pi\n ; ( Pi = when(Ai, Bi)\n -> conj_append(Bi, istep(Si, Pi, Ci, _), Bh),\n Ph = when(Ai, Bh)\n ; conj_append(Pi, istep(Si, Pi, Ci, _), Ph)\n ),\n ':-'(Ci, Ph),\n assertz(retwist(Pi, Ci, Si))\n ),\n retract(':-'(Ci, Ph))\n ; E \\= ':-'(_, true),\n retract(E)\n )\n ),\n djiti_answer(answer(E), Z),\n retractall(Z),\n ( flag('pass-only-new'),\n pass_only_new(E)\n -> retract(pass_only_new(E))\n ; true\n )\n )\n ),\n nb_getval(wn, W),\n labelvars(B, W, N),\n nb_setval(wn, N),\n unify(B, F),\n conj_list(F, G),\n forall(\n member(H, G),\n ( djiti_assertz(H),\n ( flag('pass-only-new'),\n \\+pass_only_new(H)\n -> assertz(pass_only_new(H))\n ; true\n )\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#before>'(A, B) :-\n \\+flag(restricted),\n A,\n B.\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#biconditional>'(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, B)|C], D) :-\n \\+flag(restricted),\n within_scope(_),\n ( nb_getval(bnet, done)\n -> true\n ; bnet,\n nb_setval(bnet, done)\n ),\n bvar(A),\n bval(B),\n bcon(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, B)], C, D).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#binaryEntropy>'(A, B) :-\n \\+flag(restricted),\n getnumber(A, C),\n ( C =:= 0.0\n -> B is 0.0\n ; ( C =:= 1.0\n -> B is 0.0\n ; B is -(C*log(C)+(1-C)*log(1-C))/log(2)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#calculate>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], C) :-\n \\+flag(restricted),\n findall(U,\n ( member(V, B),\n getnumber(V, U)\n ),\n W\n ),\n read_term_from_atom(A, D, [variables(W)]),\n catch(C is D, _, fail).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#call>'(A, B) :-\n \\+flag(restricted),\n nonvar(A),\n A \\= [_,_],\n !,\n when(\n ( nonvar(B)\n ),\n ( reset_gensym,\n tmp_file(Tmp1),\n open(Tmp1, write, Ws1, [encoding(utf8)]),\n tell(Ws1),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(C, D),\n format('@prefix ~w ~w.~n', [C, D])\n ),\n nl\n ),\n labelvars(A, 0, _),\n wt(A),\n write('.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp2),\n open(Tmp2, write, Ws2, [encoding(utf8)]),\n tell(Ws2),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(E, F),\n format('@prefix ~w ~w.~n', [E, F])\n ),\n nl\n ),\n labelvars(B, 0, _),\n write('{'),\n wt(B),\n write('} => {'),\n wt(B),\n write('}.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp3),\n !,\n ( current_prolog_flag(windows, true)\n -> A1 = ['cmd.exe', '/C']\n ; A1 = []\n ),\n ( current_prolog_flag(argv, Argv),\n append(Argu, ['--'|_], Argv)\n -> append(Argu, ['--'], A2)\n ; A2 = ['eye']\n ),\n ( flag(blogic)\n -> A3 = ['--blogic']\n ; A3 = ['']\n ),\n append([A1, A2, ['--nope', A3, Tmp1, '--query', Tmp2, '>', Tmp3]], A4),\n findall([G, ' '],\n ( member(G, A4)\n ),\n H\n ),\n flatten(H, I),\n atomic_list_concat(I, J),\n ( catch(exec(J, _), _, fail)\n -> n3_n3p(Tmp3, semantics),\n absolute_uri(Tmp3, Tmp),\n atomic_list_concat(['<', Tmp, '>'], Res),\n semantics(Res, L),\n delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n L \\= []\n ; delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n fail\n )\n )\n ).\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#call>'(Sc, A) :-\n \\+flag(restricted),\n within_scope(Sc),\n nonvar(A),\n conjify(A, B),\n catch(call(B), _, fail),\n ( flag(nope)\n -> true\n ; copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(B, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#call>'(Sc, B)), C),\n istep('<>', B, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#call>'(Sc, B), C)\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#cartesianProduct>'(A, B) :-\n \\+flag(restricted),\n findall(C,\n ( cartesian(A, C)\n ),\n B\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#closure>'(Sc, A) :-\n \\+flag(restricted),\n within_scope(Sc),\n hstep(A, _).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#compoundTerm>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], C) :-\n \\+flag(restricted),\n atomify(B, D),\n read_term_from_atom(A, C, [variables(D)]).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#cov>'(A, B) :-\n \\+flag(restricted),\n cov(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'(A, B) :-\n \\+flag(restricted),\n atomify(A, C),\n D =.. C,\n ( B = true\n -> catch(call(D), _, fail)\n ; \\+catch(call(D), _, fail)\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#exec>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( exec(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#fail>'(A, B) :-\n \\+flag(restricted),\n nonvar(A),\n A \\= [_,_],\n !,\n when(\n ( nonvar(B)\n ),\n ( reset_gensym,\n tmp_file(Tmp1),\n open(Tmp1, write, Ws1, [encoding(utf8)]),\n tell(Ws1),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(C, D),\n format('@prefix ~w ~w.~n', [C, D])\n ),\n nl\n ),\n labelvars(A, 0, _),\n wt(A),\n write('.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp2),\n open(Tmp2, write, Ws2, [encoding(utf8)]),\n tell(Ws2),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(E, F),\n format('@prefix ~w ~w.~n', [E, F])\n ),\n nl\n ),\n labelvars(B, 0, _),\n write('{'),\n wt(B),\n write('} => {'),\n wt(B),\n write('}.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp3),\n !,\n ( current_prolog_flag(windows, true)\n -> A1 = ['cmd.exe', '/C']\n ; A1 = []\n ),\n ( current_prolog_flag(argv, Argv),\n append(Argu, ['--'|_], Argv)\n -> append(Argu, ['--'], A2)\n ; A2 = ['eye']\n ),\n ( flag(blogic)\n -> A3 = ['--blogic']\n ; A3 = ['']\n ),\n append([A1, A2, ['--nope', A3, Tmp1, '--query', Tmp2, '>', Tmp3]], A4),\n findall([G, ' '],\n ( member(G, A4)\n ),\n H\n ),\n flatten(H, I),\n atomic_list_concat(I, J),\n ( catch(exec(J, _), _, fail)\n -> n3_n3p(Tmp3, semantics),\n absolute_uri(Tmp3, Tmp),\n atomic_list_concat(['<', Tmp, '>'], Res),\n semantics(Res, L),\n delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n L = []\n ; delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n fail\n )\n )\n ).\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#fail>'(A, B) :-\n \\+flag(restricted),\n within_scope(A),\n \\+catch(call(B), _, fail).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#fileString>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n read_file_to_string(A, C, []),\n ( string_concat(D, \"\\n\", C)\n -> true\n ; D = C\n ),\n atom_string(B, D).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>'(A, B) :-\n \\+flag(restricted),\n call_cleanup(A, B),\n ( flag(nope)\n -> true\n ; conj_append(A, B, C),\n copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(C, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>'(A, B)), D),\n istep('<>', C, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#finalize>'(A, B), D)\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(A, B) :-\n \\+flag(restricted),\n nonvar(A),\n A \\= [_,_],\n !,\n when(\n ( nonvar(B)\n ),\n ( reset_gensym,\n tmp_file(Tmp1),\n open(Tmp1, write, Ws1, [encoding(utf8)]),\n tell(Ws1),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(C, D),\n format('@prefix ~w ~w.~n', [C, D])\n ),\n nl\n ),\n labelvars(A, 0, _),\n wt(A),\n write('.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp2),\n open(Tmp2, write, Ws2, [encoding(utf8)]),\n tell(Ws2),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(E, F),\n format('@prefix ~w ~w.~n', [E, F])\n ),\n nl\n ),\n write('{'),\n wt('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(_, B)),\n write('} => {'),\n wt('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(_, B)),\n write('}.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp3),\n !,\n ( current_prolog_flag(windows, true)\n -> A1 = ['cmd.exe', '/C']\n ; A1 = []\n ),\n ( current_prolog_flag(argv, Argv),\n append(Argu, ['--'|_], Argv)\n -> append(Argu, ['--'], A2)\n ; A2 = ['eye']\n ),\n ( flag(blogic)\n -> A3 = ['--blogic']\n ; A3 = ['']\n ),\n append([A1, A2, ['--nope', A3, Tmp1, '--query', Tmp2, '>', Tmp3]], A4),\n findall([G, ' '],\n ( member(G, A4)\n ),\n H\n ),\n flatten(H, I),\n atomic_list_concat(I, J),\n ( catch(exec(J, _), _, fail)\n -> n3_n3p(Tmp3, semantics),\n absolute_uri(Tmp3, Tmp),\n atomic_list_concat(['<', Tmp, '>'], Res),\n semantics(Res, L),\n conj_list(K, L),\n labelvars(K, 0, _),\n B = [_, _, M],\n K = '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(_, [_, _, M]),\n delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3)\n ; delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n fail\n )\n )\n ).\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(Sc, [A, B, C]) :-\n \\+flag(restricted),\n within_scope(Sc),\n nonvar(B),\n \\+is_list(B),\n catch(findall(A, B, E), _, E = []),\n ( flag(warn)\n -> copy_term_nat([A, B, E], [Ac, Bc, Ec]),\n labelvars([Ac, Bc, Ec], 0, _),\n ( fact('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(Sc, [Ac, Bc, G]))\n -> ( E \\= G\n -> format(user_error, '** WARNING ** conflicting_findall_answers ~w VERSUS ~w~n', [[A, B, G], [A, B, E]]),\n flush_output(user_error)\n ; true\n )\n ; assertz(fact('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(Sc, [Ac, Bc, Ec])))\n )\n ; true\n ),\n E = C.\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#firstRest>'([A|B], [A, B]) :-\n \\+flag(restricted).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#format>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, D),\n preformat(B, E),\n format_to_chars(D, E, F),\n atom_codes(C, F)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphCopy>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#labelvars>'(A, C),\n conj_list(C, L),\n sort(L, M),\n conj_list(K, M),\n unify(K, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphDifference>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( makevars(A, C, delta),\n difference(C, D),\n unify(D, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphIntersection>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( intersect(A, M),\n unify(M, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphList>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( unify(A, C),\n conj_list(C, D),\n ( nonvar(B)\n -> cflat(B, E),\n ( ground(E)\n -> distinct(E, D)\n ; D = E\n )\n ; ( ground(D)\n -> distinct(D, B)\n ; B = D\n )\n )\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphMember>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( conj_list(A, C),\n member(D, C),\n unify(D, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphPair>'((A, B), [A, B]) :-\n \\+flag(restricted).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#hmac-sha>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n flag('hmac-key', Key),\n hmac_sha(Key, A, C, [algorithm(sha1)]),\n atom_codes(D, C),\n base64xml(D, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#ignore>'(Sc, A) :-\n \\+flag(restricted),\n within_scope(Sc),\n nonvar(A),\n ( catch(call(A), _, fail)\n -> ( flag(nope)\n -> true\n ; copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#ignore>'(Sc, A)), R),\n istep('<>', A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#ignore>'(Sc, A), R)\n )\n ; true\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#label>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( atom(A),\n ( sub_atom(A, _, 19, _, '/.well-known/genid/')\n -> ( sub_atom(A, I, 1, _, '#')\n -> J is I+1,\n sub_atom(A, J, _, 1, B)\n ; B = ''\n )\n ; atom_concat(some, C, A),\n atomic_list_concat(['sk_', C], B)\n )\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#labelvars>'(A, B) :-\n \\+flag(restricted),\n copy_term_nat(A, C),\n labelvars(C, 0, _),\n term_index(C, D),\n ( got_labelvars(C, D, B)\n -> true\n ; copy_term_nat(A, B),\n labelvars(B, 0, _, avar),\n assertz(got_labelvars(C, D, B))\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#length>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( ( getlist(A, C)\n -> true\n ; conj_list(A, D),\n ( ground(D)\n -> distinct(D, C)\n ; C = D\n )\n ),\n length(C, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#match>'(_, B) :-\n \\+flag(restricted),\n \\+ \\+catch(call(B), _, fail).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#max>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( bmax(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#min>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( bmin(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#multisetEqualTo>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n nonvar(B)\n ),\n ( sort(0, @=<, A, C),\n sort(0, @=<, B, C)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#multisetNotEqualTo>'(A, B) :-\n \\+flag(restricted),\n \\+'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#multisetEqualTo>'(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#notLabel>'(A, B) :-\n \\+flag(restricted),\n \\+'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#label>'(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#numeral>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( getnumber(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#optional>'(Sc, A) :-\n \\+flag(restricted),\n within_scope(Sc),\n nonvar(A),\n ( \\+catch(call(A), _, fail)\n -> true\n ; catch(call(A), _, fail),\n ( flag(nope)\n -> true\n ; copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#optional>'(Sc, A)), R),\n istep('<>', A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#optional>'(Sc, A), R)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#pcc>'([A, B], C) :-\n \\+flag(restricted),\n pcc([A, B], C).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#prefix>'(Sc, literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n within_scope(Sc),\n with_output_to_codes(wh, C),\n atom_codes(A, C),\n retractall(wpfx(_)).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#propertyChainExtension>'([A], [B, C]) :-\n \\+flag(restricted),\n !,\n D =.. [A, B, C],\n catch(call(D), _, fail).\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#propertyChainExtension>'([A|B], [C, D]) :-\n \\+flag(restricted),\n E =.. [A, C, F],\n catch(call(E), _, fail),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#propertyChainExtension>'(B, [F, D]).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#random>'([A|B], C) :-\n \\+flag(restricted),\n term_index([A|B], I),\n ( B \\= [],\n got_random([A|B], I, C)\n -> true\n ; catch(nb_getval(random, D), _, D = 16127),\n E is mod(1046527*D+16769023, 1073676287),\n nb_setval(random, E),\n C is mod(E, A),\n ( B \\= []\n -> assertz(got_random([A|B], I, C))\n ; true\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#reverse>'(A, B) :-\n \\+flag(restricted),\n reverse(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#rms>'(A, B) :-\n \\+flag(restricted),\n rms(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#roc>'(St, [Sen, Asp]) :-\n \\+flag(restricted),\n getnumber(St, K),\n ( getnumber(Sen, S)\n -> Asp is 1-(1-exp(-K*(S-1)))*(1+exp(K))/(1+exp(-K*(S-1)))/(1-exp(K))\n ; getnumber(Asp, A),\n Sen is (1-exp(-K*A))*(1+exp(-K))/(1+exp(-K*A))/(1-exp(-K))\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#sha>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n sha_hash(A, C, [algorithm(sha1)]),\n atom_codes(D, C),\n base64xml(D, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#sigmoid>'(A, B) :-\n \\+flag(restricted),\n getnumber(A, C),\n B is 1/(1+exp(-C)).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#skolem>'(X, Y) :-\n \\+flag(restricted),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(Y, X),\n ( \\+keep_skolem(Y)\n -> assertz(keep_skolem(Y))\n ; true\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#sort>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( sort(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#std>'(A, B) :-\n \\+flag(restricted),\n std(A, B).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#stringEscape>'(literal(X, Y), literal(Z, Y)) :-\n \\+flag(restricted),\n when(\n ( ground(X)\n ),\n ( atom_codes(X, U),\n escape_string(U, V),\n atom_codes(Z, V)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#stringReverse>'(literal(X, Y), literal(Z, Y)) :-\n \\+flag(restricted),\n when(\n ( ground(X)\n ),\n ( atom_codes(X, U),\n reverse(U, V),\n atom_codes(Z, V)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#stringSplit>'([literal(X, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))],\n Z) :-\n \\+flag(restricted),\n when(\n ( ground([X, Y])\n ),\n ( atom_codes(X, U),\n atom_codes(Y, C),\n ( C = []\n -> findall(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')),\n ( member(B, U),\n atom_codes(A, [B])\n ),\n Z\n )\n ; escape_string(V, C),\n esplit_string(U, V, [], W),\n findall(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')),\n ( member(B, W),\n atom_codes(A, B)\n ),\n Z\n )\n )\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#subsequence>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( sub_list(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#trace>'(X, Y) :-\n \\+flag(restricted),\n tell(user_error),\n write('TRACE '),\n ( ( var(X)\n ; findvar(X, beta)\n )\n -> copy_term_nat(Y, Z),\n wg(Z)\n ; writeq(Y)\n ),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transpose>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( e_transpose(A, B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tripleList>'(A, [B, C, D]) :-\n \\+flag(restricted),\n A =.. [C, B, D].\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(X, Y) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ; ground(Y)\n ),\n ( ( is_list(Y),\n length(Y, I),\n I < 8\n -> Z =.. [tuple, X|Y]\n ; Z = tuple(X, Y)\n ),\n ( call(Z)\n -> true\n ; var(X),\n nb_getval(tuple, M),\n N is M+1,\n nb_setval(tuple, N),\n atom_number(A, N),\n nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 't_', A, '>'], X),\n assertz(Z)\n )\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#unique>'(A, B) :-\n \\+flag(restricted),\n ( got_unique(A, B)\n -> fail\n ; assertz(got_unique(A, B))\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#whenGround>'(A, B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( findvars(A, C, delta),\n C \\= []\n -> true\n ; catch(call(B), _, A = B)\n )\n ).\n\n'<http://eulersharp.sourceforge.net/2003/03swap/log-rules#wwwFormEncode>'(X, literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( ( ground(X)\n -> ( number(X)\n -> atom_number(T, X)\n ; X = literal(T, _)\n ),\n www_form_encode(T, Z),\n atom_codes(Z, U),\n subst([[[0'%, 0'2, 0'0], [0'+]]], U, V),\n atom_codes(Y, V)\n ; www_form_encode(X, Y)\n )\n )\n ).\n\n'<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>'(X, Y) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( X = [Y|Z],\n nonvar(Z)\n )\n ),\n !.\n\n'<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'(X, []) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( X = [_]\n )\n ),\n !.\n'<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'(X, '<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>') :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( X = [_]\n )\n ),\n !.\n'<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'(X, Y) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( X = [_|Y]\n )\n ),\n !.\n\n'<http://www.w3.org/2000/10/swap/crypto#md5>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n (\n md5_hash(A, B, [])\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/crypto#sha>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n ( sha_hash(A, C, [algorithm(sha1)]),\n hash_atom(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/crypto#sha256>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n ( sha_hash(A, C, [algorithm(sha256)]),\n hash_atom(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/crypto#sha512>'(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n ( sha_hash(A, C, [algorithm(sha512)]),\n hash_atom(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/graph#difference>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( makevars(A, C, delta),\n difference(C, D),\n unify(D, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/graph#intersection>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( intersect(A, C),\n unify(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/graph#length>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( conj_list(A, D),\n ( ground(D)\n -> distinct(D, C)\n ; C = D\n ),\n length(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/graph#list>'(A, B) :-\n conj_list(A, B).\n\n'<http://www.w3.org/2000/10/swap/graph#member>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphMember>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/graph#union>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( conjoin(A, C),\n unify(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#append>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n ( member(D, C),\n var(D),\n var(B)\n -> true\n ; append(C, B)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#first>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n C = [B|D],\n nonvar(D)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#firstRest>'([A|B], [A, B]).\n\n'<http://www.w3.org/2000/10/swap/list#in>'(A, B) :-\n when(\n ( nonvar(B)\n ),\n ( getlist(B, C),\n member(A, C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#iterate>'(A, [B, C]) :-\n when(\n ( nonvar(A)\n ),\n ( nth0(B, A, C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#last>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n last(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#length>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( ( getlist(A, C)\n -> true\n ; conj_list(A, D),\n ( ground(D)\n -> distinct(D, C)\n ; C = D\n )\n ),\n length(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#map>'([A, B], C) :-\n when(\n ( nonvar(A),\n nonvar(B)\n ),\n ( getlist(A, D),\n findall(E,\n ( member(F, D),\n G =.. [B, F, E],\n G\n ),\n C\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#member>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n member(B, C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#memberAt>'([A, B], C) :-\n when(\n ( nonvar(A)\n ),\n ( nth0(B, A, C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#multisetEqualTo>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#multisetEqualTo>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/list#multisetNotEqualTo>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#multisetNotEqualTo>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/list#remove>'([A, B], C) :-\n when(\n ( nonvar(A),\n nonvar(B)\n ),\n ( findall(I,\n ( member(I, A),\n I \\= B\n ),\n C\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#removeAt>'([A, B], C) :-\n when(\n ( nonvar(A)\n ),\n ( nth0(B, A, D),\n findall(I,\n ( member(I, A),\n I \\= D\n ),\n C\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#removeDuplicates>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n list_to_set(C, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#rest>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( getlist(A, C),\n C = [_|B]\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#setEqualTo>'(A, B) :-\n when(\n ( nonvar(A),\n nonvar(B)\n ),\n ( getlist(A, C),\n getlist(B, D),\n sort(C, E),\n sort(D, E)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/list#setNotEqualTo>'(A, B) :-\n \\+'<http://www.w3.org/2000/10/swap/list#setEqualTo>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/list#unique>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( sort(A, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#becomes>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#becomes>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/log#bound>'(X, Y) :-\n ( nonvar(X)\n -> Y = true\n ; Y = false\n ).\n\n'<http://www.w3.org/2000/10/swap/log#callWithCleanup>'(A, B) :-\n call_cleanup(A, B),\n ( flag(nope)\n -> true\n ; conj_append(A, B, C),\n copy_term_nat('<http://www.w3.org/2000/10/swap/log#implies>'(C, '<http://www.w3.org/2000/10/swap/log#callWithCleanup>'(A, B)), D),\n istep('<>', C, '<http://www.w3.org/2000/10/swap/log#callWithCleanup>'(A, B), D)\n ).\n\n'<http://www.w3.org/2000/10/swap/log#collectAllIn>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#findall>'(B, A).\n\n'<http://www.w3.org/2000/10/swap/log#conclusion>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( reset_gensym,\n tmp_file(Tmp1),\n open(Tmp1, write, Ws1, [encoding(utf8)]),\n tell(Ws1),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(C, D),\n format('@prefix ~w ~w.~n', [C, D])\n ),\n nl\n ),\n labelvars(A, 0, _),\n wt(A),\n write('.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp2),\n !,\n ( current_prolog_flag(windows, true)\n -> A1 = ['cmd.exe', '/C']\n ; A1 = []\n ),\n ( current_prolog_flag(argv, Argv),\n append(Argu, ['--'|_], Argv)\n -> append(Argu, ['--'], A2)\n ; A2 = ['eye']\n ),\n ( flag(blogic)\n -> A3 = ['--blogic']\n ; A3 = ['']\n ),\n append([A1, A2, ['--nope', A3, Tmp1, '--pass-all', '>', Tmp2]], A4),\n findall([G, ' '],\n ( member(G, A4)\n ),\n H\n ),\n flatten(H, I),\n atomic_list_concat(I, J),\n ( catch(exec(J, _), _, fail)\n -> n3_n3p(Tmp2, semantics),\n absolute_uri(Tmp2, Tmp),\n atomic_list_concat(['<', Tmp, '>'], Res),\n semantics(Res, L),\n conj_list(B, L),\n labelvars(B, 0, _),\n delete_file(Tmp1),\n delete_file(Tmp2)\n ; delete_file(Tmp1),\n delete_file(Tmp2),\n fail\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#conjunction>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( conjoin(A, M),\n unify(M, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#content>'(A, B) :-\n \\+flag(restricted),\n '<http://www.w3.org/2000/10/swap/log#semantics>'(A, C),\n '<http://www.w3.org/2000/10/swap/log#n3String>'(C, B).\n\n'<http://www.w3.org/2000/10/swap/log#dtlit>'([A, B], C) :-\n when(\n ( ground(A)\n ; nonvar(C)\n ),\n ( ground(A),\n ( var(B)\n -> ( member(B, ['<http://www.w3.org/2001/XMLSchema#integer>', '<http://www.w3.org/2001/XMLSchema#double>',\n '<http://www.w3.org/2001/XMLSchema#date>', '<http://www.w3.org/2001/XMLSchema#time>', '<http://www.w3.org/2001/XMLSchema#dateTime>',\n '<http://www.w3.org/2001/XMLSchema#yearMonthDuration>', '<http://www.w3.org/2001/XMLSchema#dayTimeDuration>', '<http://www.w3.org/2001/XMLSchema#duration>']),\n dtlit([A, B], C),\n getnumber(C, D),\n dtlit([_, B], D)\n -> true\n ; ( dtlit([A, '<http://www.w3.org/2001/XMLSchema#boolean>'], C),\n getbool(C, _),\n B = '<http://www.w3.org/2001/XMLSchema#boolean>'\n -> true\n ; B = '<http://www.w3.org/2001/XMLSchema#string>',\n C = A\n )\n )\n ; A = literal(E, _),\n ( B = prolog:atom\n -> C = E\n ; C = literal(E, type(B))\n ),\n !\n )\n ; nonvar(C),\n dtlit([A, B], C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#equalTo>'(X, Y) :-\n unify(X, Y).\n\n'<http://www.w3.org/2000/10/swap/log#forAllIn>'([A, B], Sc) :-\n within_scope(Sc),\n when(\n ( nonvar(A),\n nonvar(B)\n ),\n ( forall(A, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#hasPrefix>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( pfx(_, A)\n -> B = true\n ; B = false\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#ifThenElseIn>'(A, B) :-\n \\+flag(restricted),\n nonvar(B),\n B \\= [_,_],\n !,\n when(\n ( nonvar(A)\n ),\n ( reset_gensym,\n tmp_file(Tmp1),\n open(Tmp1, write, Ws1, [encoding(utf8)]),\n tell(Ws1),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(C, D),\n format('@prefix ~w ~w.~n', [C, D])\n ),\n nl\n ),\n labelvars(B, 0, _),\n wt(B),\n write('.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp2),\n open(Tmp2, write, Ws2, [encoding(utf8)]),\n tell(Ws2),\n ( flag('no-qnames')\n -> true\n ; forall(\n pfx(E, F),\n format('@prefix ~w ~w.~n', [E, F])\n ),\n nl\n ),\n write('{'),\n wt('<http://www.w3.org/2000/10/swap/log#ifThenElseIn>'(A, _)),\n write('} => {'),\n wt('<http://www.w3.org/2000/10/swap/log#ifThenElseIn>'(A, _)),\n write('}.'),\n nl,\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n tmp_file(Tmp3),\n !,\n ( current_prolog_flag(windows, true)\n -> A1 = ['cmd.exe', '/C']\n ; A1 = []\n ),\n ( current_prolog_flag(argv, Argv),\n append(Argu, ['--'|_], Argv)\n -> append(Argu, ['--'], A2)\n ; A2 = ['eye']\n ),\n ( flag(blogic)\n -> A3 = ['--blogic']\n ; A3 = ['']\n ),\n append([A1, A2, ['--nope', A3, Tmp1, '--query', Tmp2, '>', Tmp3]], A4),\n findall([G, ' '],\n ( member(G, A4)\n ),\n H\n ),\n flatten(H, I),\n atomic_list_concat(I, J),\n ( catch(exec(J, _), _, fail)\n -> n3_n3p(Tmp3, semantics),\n absolute_uri(Tmp3, Tmp),\n atomic_list_concat(['<', Tmp, '>'], Res),\n semantics(Res, L),\n conj_list(K, L),\n labelvars(K, 0, _),\n A = M,\n K = '<http://www.w3.org/2000/10/swap/log#ifThenElseIn>'(M, _),\n delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3)\n ; delete_file(Tmp1),\n delete_file(Tmp2),\n delete_file(Tmp3),\n fail\n )\n )\n ).\n'<http://www.w3.org/2000/10/swap/log#ifThenElseIn>'([A, B, C], Sc) :-\n within_scope(Sc),\n when(\n ( nonvar(A),\n nonvar(B),\n nonvar(C)\n ),\n ( if_then_else(A, B, C)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#implies>'(X, Y) :-\n implies(U, V, _),\n unify(U, X),\n unify(V, Y),\n ( commonvars(X, Y, [])\n -> labelvars(Y, 0, _, avar)\n ; true\n ),\n ( var(Y)\n -> true\n ; Y \\= answer(_, _, _),\n Y \\= (answer(_, _, _), _)\n ).\n\n'<http://www.w3.org/2000/10/swap/log#includes>'(X, Y) :-\n within_scope(X),\n !,\n when(\n ( nonvar(Y)\n ),\n ( Y\n )\n ).\n'<http://www.w3.org/2000/10/swap/log#includes>'(X, Y) :-\n when(\n ( nonvar(X),\n nonvar(Y)\n ),\n ( conj_list(X, A),\n conj_list(Y, B),\n includes(A, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#includesNotBind>'(X, Y) :-\n within_scope(X),\n !,\n when(\n ( nonvar(Y)\n ),\n ( \\+ \\+call(Y)\n )\n ).\n'<http://www.w3.org/2000/10/swap/log#includesNotBind>'(X, Y) :-\n when(\n ( nonvar(X),\n nonvar(Y)\n ),\n ( conj_list(X, A),\n conj_list(Y, B),\n \\+ \\+includes(A, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#inferences>'(A, B) :-\n '<http://www.w3.org/2000/10/swap/log#conclusion>'(A, C),\n ( nonvar(B)\n -> '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#graphIntersection>'([B,C], B)\n ; B = C\n ).\n\n'<http://www.w3.org/2000/10/swap/log#langlit>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(A, lang(B))).\n\n'<http://www.w3.org/2000/10/swap/log#localN3String>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n term_variables(A, V),\n labelvars([A, V], 0, _, avar),\n with_output_to_chars((wq(V, allv), wt(A)), E),\n escape_string(E, F),\n atom_codes(B, F).\n\n'<http://www.w3.org/2000/10/swap/log#localName>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n ( sub_atom(A, 1, _, 1, C),\n (\n sub_atom_last(C, _, 1, N, '#') ->\n sub_atom(C, _, N, 0, B)\n ;\n sub_atom_last(C, _, 1, N, '/') ->\n sub_atom(C, _, N, 0, B)\n ;\n sub_atom_last(C, _, 1, N, ':') ->\n sub_atom(C, _, N, 0, B)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#n3String>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n ( n3s(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>')))\n -> true\n ; retractall(wpfx(_)),\n with_output_to_chars(wh, C1),\n \\+ (C1 = [], \\+flag('no-qnames')),\n numbervars(A),\n with_output_to_chars(wt(A), C2),\n append(C1, C2, C),\n escape_string(C, D),\n atom_codes(B, D),\n assertz(n3s(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))))\n ).\n\n'<http://www.w3.org/2000/10/swap/log#namespace>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ),\n ( sub_atom(A, 1, _, 1, C),\n (\n sub_atom_last(C, N, 1, _, '#') ->\n M is N+1,\n sub_atom(C, 0, M, _, B)\n ;\n sub_atom_last(C, N, 1, _, '/') ->\n M is N+1,\n sub_atom(C, 0, M, _, B)\n ;\n sub_atom_last(C, N, 1, _, ':') ->\n M is N+1,\n sub_atom(C, 0, M, _, B)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#notEqualTo>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( \\+'<http://www.w3.org/2000/10/swap/log#equalTo>'(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#notIncludes>'(X, Y) :-\n ignore(within_scope(X)),\n \\+'<http://www.w3.org/2000/10/swap/log#includes>'(X, Y).\n\n'<http://www.w3.org/2000/10/swap/log#parsedAsN3>'(literal(A, _), B) :-\n atom_codes(A, C),\n escape_string(D, C),\n atom_codes(E, D),\n tmp_file(Tmp),\n open(Tmp, write, Ws, [encoding(utf8)]),\n tell(Ws),\n writef(E, []),\n told,\n ( flag('output', Output)\n -> tell(Output)\n ; true\n ),\n atomic_list_concat(['<file://', Tmp, '>'], F),\n '<http://www.w3.org/2000/10/swap/log#semantics>'(F, B).\n\n'<http://www.w3.org/2000/10/swap/log#phrase>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], C) :-\n read_term_from_atom(A, D, [variables(B)]),\n findall(E,\n ( member(literal(E, type('<http://www.w3.org/2001/XMLSchema#string>')), C)\n ),\n F\n ),\n phrase(D, F, []).\n\n'<http://www.w3.org/2000/10/swap/log#prefix>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( nonvar(A)\n ; nonvar(B)\n ),\n ( pfx(C, A),\n sub_atom(C, 0, _, 1, B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#racine>'(A, B) :-\n when(\n ( nonvar(A)\n ),\n ( sub_atom(A, 1, _, 1, C),\n sub_atom(C, N, 1, _, '#'),\n sub_atom(C, 0, N, _, D),\n atomic_list_concat(['<', D, '>'], B)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#rawType>'(A, B) :-\n nonvar(A),\n raw_type(A, C),\n C = B.\n\n'<http://www.w3.org/2000/10/swap/log#repeat>'(A, B) :-\n C is A-1,\n between(0, C, B).\n\n'<http://www.w3.org/2000/10/swap/log#semantics>'(X, Y) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( ( semantics(X, L)\n -> conj_list(Y, L)\n ; sub_atom(X, 0, 1, _, '<'),\n sub_atom(X, _, 1, 0, '>'),\n sub_atom(X, 1, _, 1, Z),\n catch(\n n3_n3p(Z, semantics),\n Exc,\n ( format(user_error, '** ERROR ** ~w **~n', [Exc]),\n flush_output(user_error),\n fail\n )\n ),\n semantics(X, L),\n conj_list(Y, L)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#semanticsOrError>'(X, Y) :-\n \\+flag(restricted),\n when(\n ( nonvar(X)\n ),\n ( ( semantics(X, L)\n -> conj_list(Y, L)\n ; sub_atom(X, 0, 1, _, '<'),\n sub_atom(X, _, 1, 0, '>'),\n sub_atom(X, 1, _, 1, Z),\n catch(\n n3_n3p(Z, semantics),\n Exc,\n assertz(semantics(X, [literal(Exc, type('<http://www.w3.org/2001/XMLSchema#string>'))]))\n ),\n semantics(X, L),\n conj_list(Y, L)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#skolem>'(X, Y) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tuple>'(Y, X),\n ( \\+keep_skolem(Y)\n -> assertz(keep_skolem(Y))\n ; true\n ).\n\n'<http://www.w3.org/2000/10/swap/log#trace>'(A, B) :-\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#trace>'(A, B).\n\n'<http://www.w3.org/2000/10/swap/log#uri>'(X, Y) :-\n when(\n ( nonvar(X)\n ; nonvar(Y)\n ),\n ( atomic(X),\n ( atom_concat(some, V, X)\n -> nb_getval(var_ns, Sns),\n atomic_list_concat(['<', Sns, 'sk_', V, '>'], U)\n ; ( atom_concat(avar, V, X)\n -> atomic_list_concat(['<http://eyereasoner.github.io/var#x_', V, '>'], U)\n ; U = X\n )\n ),\n sub_atom(U, 1, _, 1, Z),\n atomic_list_concat(['<', Z, '>'], U),\n Y = literal(Z, type('<http://www.w3.org/2001/XMLSchema#string>')),\n !\n ; nonvar(Y),\n Y = literal(Z, type('<http://www.w3.org/2001/XMLSchema#string>')),\n atomic_list_concat(['<', Z, '>'], X)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/log#uuid>'(X, literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground(X)\n ),\n ( '<http://www.w3.org/2000/10/swap/log#uri>'(X, literal(U, type('<http://www.w3.org/2001/XMLSchema#string>'))),\n ( \\+got_uuid(U)\n -> uuid(Y, [uri(U)]),\n assertz(got_uuid(U))\n ; true\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#absoluteValue>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, U),\n Y is abs(U)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#acos>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is acos(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#acosh>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is acosh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#asin>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is asin(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#asinh>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is asinh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#atan>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is atan(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#atan2>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n Z is atan(U/V)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#atanh>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, W),\n Y is atanh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#ceiling>'(X, Y) :-\n when(\n ( ground(X)\n ),\n (\n getnumber(X, U),\n Y is ceiling(U)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#cos>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is cos(U),\n !\n ; getnumber(Y, W),\n X is acos(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#cosh>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is cosh(U),\n !\n ; getnumber(Y, W),\n X is acosh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#degrees>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is U*180/pi,\n !\n ; getnumber(Y, W),\n X is W*pi/180\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#difference>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n Z is U-V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#equalTo>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U =:= V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#exponentiation>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ; ground([X, Z])\n ),\n ( getnumber(X, U),\n ( getnumber(Y, V),\n Z is U**V,\n !\n ; getnumber(Z, W),\n W =\\= 0,\n U =\\= 0,\n Y is log(W)/log(U)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#floor>'(X, Y) :-\n when(\n ( ground(X)\n ),\n (\n getnumber(X, U),\n Y is floor(U)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#greaterThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U > V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#integerQuotient>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n ( V =\\= 0\n -> Z is round(floor(U/V))\n ; throw(zero_division('<http://www.w3.org/2000/10/swap/math#integerQuotient>'([X, Y], Z)))\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#lessThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U < V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#logarithm>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ; ground([X, Z])\n ),\n ( getnumber(X, U),\n ( getnumber(Y, V),\n V =\\= 0,\n U =\\= 0,\n Z is log(U)/log(V),\n !\n ; getnumber(Z, W),\n Y is U**(1/W)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#max>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( max_list(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#memberCount>'(X, Y) :-\n when(\n ( nonvar(X)\n ),\n ( ( getlist(X, Z)\n -> true\n ; conj_list(X, U),\n ( ground(U)\n -> distinct(U, Z)\n ; Z = U\n )\n ),\n length(Z, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#min>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( min_list(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#negation>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is -U,\n !\n ; getnumber(Y, W),\n X is -W\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#notEqualTo>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U =\\= V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#notGreaterThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U =< V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#notLessThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n U >= V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#product>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( product(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#quotient>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n ( V =\\= 0\n -> Z is U/V\n ; throw(zero_division('<http://www.w3.org/2000/10/swap/math#quotient>'([X, Y], Z)))\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#radians>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is U*pi/180,\n !\n ; getnumber(Y, W),\n X is W*180/pi\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#remainder>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n ( V =\\= 0\n -> Z is U-V*round(floor(U/V))\n ; throw(zero_division('<http://www.w3.org/2000/10/swap/math#remainder>'([X, Y], Z)))\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#rounded>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( getnumber(X, U),\n Y is round(round(U))\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#roundedTo>'([X, Y], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( getnumber(X, U),\n getnumber(Y, V),\n F is 10**floor(V),\n Z is round(round(U*F))/F\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#sin>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is sin(U),\n !\n ; getnumber(Y, W),\n X is asin(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#sinh>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is sinh(U),\n !\n ; getnumber(Y, W),\n X is asinh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#sum>'(X, Y) :-\n when(\n ( ground(X)\n ),\n ( sum(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#tan>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is tan(U),\n !\n ; getnumber(Y, W),\n X is atan(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/math#tanh>'(X, Y) :-\n when(\n ( ground(X)\n ; ground(Y)\n ),\n ( getnumber(X, U),\n Y is tanh(U),\n !\n ; getnumber(Y, W),\n X is atanh(W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#capitalize>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground(X)\n ),\n ( sub_atom(X, 0, 1, _, A),\n upcase_atom(A, B),\n sub_atom(X, 1, _, 0, C),\n downcase_atom(C, D),\n atom_concat(B, D, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#concatenation>'(X, Y) :-\n when(\n ( nonvar(X)\n ),\n ( getlist(X, C),\n labelvars(C, 0, _, avar),\n ( member(D, C),\n var(D),\n var(Y)\n -> true\n ; findall(S,\n ( member(A, X),\n getcodes(A, S)\n ),\n Z\n ),\n flatten(Z, E),\n atom_codes(F, E),\n Y = literal(F, type('<http://www.w3.org/2001/XMLSchema#string>'))\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#contains>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground([X, Y])\n ),\n ( sub_atom(X, _, _, _, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#containsIgnoringCase>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground([X, Y])\n ),\n ( downcase_atom(X, U),\n downcase_atom(Y, V),\n sub_atom(U, _, _, _, V)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#containsRoughly>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground([X, Y])\n ),\n ( downcase_atom(X, R),\n downcase_atom(Y, S),\n normalize_space(atom(U), R),\n normalize_space(atom(V), S),\n sub_atom(U, _, _, _, V)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#endsWith>'(literal(X, _), literal(Y, _)) :-\n when(\n ( ground([X, Y])\n ),\n ( sub_atom(X, _, _, 0, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#equalIgnoringCase>'(literal(X, _), literal(Y, _)) :-\n when(\n ( ground([X, Y])\n ),\n ( downcase_atom(X, U),\n downcase_atom(Y, U)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#format>'([literal(A, _)|B], literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, D),\n subst([[[0'%, 0's], [0'~, 0'w]]], D, E),\n preformat(B, F),\n format_to_chars(E, F, G),\n atom_codes(C, G)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#greaterThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getstring(X, U),\n getstring(Y, V),\n U @> V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#join>'([X,Y], Z) :-\n when(\n ( nonvar(X)\n ),\n ( getlist(X, C),\n getcodes(Y, D),\n labelvars(C, 0, _, avar),\n ( member(E, C),\n var(E),\n var(Z)\n -> true\n ; findall([D,S],\n ( member(A, X),\n getcodes(A, S)\n ),\n U\n ),\n flatten(U, V),\n ( V = []\n -> F = V\n ; append(D, F, V)\n ),\n atom_codes(G, F),\n Z = literal(G, type('<http://www.w3.org/2001/XMLSchema#string>'))\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#lessThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getstring(X, U),\n getstring(Y, V),\n U @< V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#length>'(literal(A, _), B) :-\n when(\n ( ground(A)\n ),\n ( sub_atom(A, 0, B, 0, _)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#lowerCase>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground(X)\n ),\n ( downcase_atom(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#matches>'(literal(X, _), literal(Y, _)) :-\n when(\n ( ground([X, Y])\n ),\n ( regex(Y, X, _)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#notContainsRoughly>'(X, Y) :-\n \\+'<http://www.w3.org/2000/10/swap/string#containsRoughly>'(X, Y).\n\n'<http://www.w3.org/2000/10/swap/string#notEqualIgnoringCase>'(X, Y) :-\n \\+'<http://www.w3.org/2000/10/swap/string#equalIgnoringCase>'(X, Y).\n\n'<http://www.w3.org/2000/10/swap/string#notGreaterThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getstring(X, U),\n getstring(Y, V),\n U @=< V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#notLessThan>'(X, Y) :-\n when(\n ( ground([X, Y])\n ),\n ( getstring(X, U),\n getstring(Y, V),\n U @>= V\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#notMatches>'(X, Y) :-\n \\+'<http://www.w3.org/2000/10/swap/string#matches>'(X, Y).\n\n'<http://www.w3.org/2000/10/swap/string#replace>'([literal(X, _),literal(Search, _),literal(Replace, _)], literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground([X,Search,Replace])\n ),\n ( ( regex(Search, X, [S|_])\n -> atom_codes(X, XC),\n string_codes(S, SC),\n atom_codes(Replace, RC),\n subst([[[0'$,0'1],SC]], RC, TC),\n subst([[SC,TC]], XC, YC),\n atom_codes(Y, YC)\n ; Y = X\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#replaceAll>'([literal(X, _),SearchList,ReplaceList], literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground([X,SearchList,ReplaceList])\n ),\n ( preformat(SearchList, SearchList2),\n preformat(ReplaceList, ReplaceList2),\n replace(SearchList2, ReplaceList2, X, Z),\n atom_string(Y, Z)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#scrape>'([literal(X, _),literal(Y, _)], literal(Z, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground([X,Y])\n ),\n ( regex(Y, X, [W|_]),\n atom_string(Z, W)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#scrapeAll>'([literal(X, _),literal(Y, _)], Z) :-\n when(\n ( ground([X,Y])\n ),\n ( scrape(X, Y, V),\n preformat(Z, V)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#search>'([literal(X, _),literal(Y, _)], Z) :-\n when(\n ( ground([X, Y])\n ),\n ( regex(Y, X, L),\n findall(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')),\n ( member(M, L),\n atom_string(A, M)\n ),\n Z\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#startsWith>'(literal(X, _), literal(Y, _)) :-\n when(\n ( ground([X, Y])\n ),\n ( sub_atom(X, 0, _, _, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#substring>'([literal(A, _), B, C], literal(D, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n !,\n when(\n ( ground([A, B, C])\n ),\n ( getint(B, I),\n getint(C, J),\n ( I < 1\n -> G is 0,\n H is J+I-1\n ; G is I-1,\n H is J\n ),\n ( H < 0\n -> D = ''\n ; sub_atom(A, G, H, _, D)\n )\n )\n ).\n'<http://www.w3.org/2000/10/swap/string#substring>'([literal(A, _), B], literal(D, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground([A, B])\n ),\n ( getint(B, I),\n sub_atom(A, 0, E, 0, _),\n J is E-I+1,\n ( I < 1\n -> G is 0,\n H is J+I-1\n ; G is I-1,\n H is J\n ),\n ( H < 0\n -> D = []\n ; sub_atom(A, G, H, _, D)\n )\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/string#upperCase>'(literal(X, Z), literal(Y, Z)) :-\n when(\n ( ground(X)\n ),\n ( upcase_atom(X, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/time#day>'(literal(X, _), literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground(X)\n ),\n ( sub_atom(X, 8, 2, _, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/time#localTime>'(literal(X, _), literal(Y, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))) :-\n when(\n ( ground(X)\n ),\n ( timestamp(Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/time#month>'(literal(X, _), literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground(X)\n ),\n ( sub_atom(X, 5, 2, _, Y)\n )\n ).\n\n'<http://www.w3.org/2000/10/swap/time#year>'(literal(X, _), literal(Y, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n when(\n ( ground(X)\n ),\n ( sub_atom(X, 0, 4, _, Y)\n )\n ).\n\n% RIF built-ins according to RIF Datatypes and Built-Ins 1.0 -- http://www.w3.org/TR/rif-dtb/\n\n% 4.1.1.1 pred:literal-not-identical\n\n'<http://www.w3.org/2007/rif-builtin-predicate#literal-not-identical>'([literal(A, B), literal(C, B)], D) :-\n \\+flag(restricted),\n when(\n ( ground([A, B, C])\n ),\n ( A \\== C\n -> D = true\n ; D = false\n )\n ).\n\n% 4.4.4 pred:iri-string\n\n'<http://www.w3.org/2007/rif-builtin-predicate#iri-string>'([A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ; nonvar(B)\n ),\n ( atom(A),\n sub_atom(A, 1, _, 1, U),\n atomic_list_concat(['<', U, '>'], A),\n !,\n ( U = B\n -> C = true\n ; C = false\n )\n ; nonvar(B),\n ( atomic_list_concat(['<', B, '>'], A)\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.1 Numeric Functions\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-add>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sum([A, B], C)\n )\n ).\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-subtract>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n C is U-V\n )\n ).\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-multiply>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n C is U*V\n )\n ).\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-divide>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( V =\\= 0\n -> C is U/V\n ; throw(zero_division('<http://www.w3.org/2007/rif-builtin-function#numeric-divide>'([A, B], C)))\n )\n )\n ).\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-integer-divide>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( V =\\= 0\n -> C is integer(floor(U/V))\n ; throw(zero_division('<http://www.w3.org/2007/rif-builtin-function#numeric-integer-divide>'([A, B], C)))\n )\n )\n ).\n\n'<http://www.w3.org/2007/rif-builtin-function#numeric-mod>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( V =\\= 0\n -> C is U-V*integer(floor(U/V))\n ; throw(zero_division('<http://www.w3.org/2007/rif-builtin-function#numeric-mod>'([A, B], C)))\n )\n )\n ).\n\n% 4.5.2.1 pred:numeric-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-equal>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U =:= V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.2.2 pred:numeric-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-less-than>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U < V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.2.3 pred:numeric-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-greater-than>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U > V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.2.4 pred:numeric-not-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-not-equal>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U =\\= V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.2.5 pred:numeric-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-less-than-or-equal>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U =< V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.5.2.6 pred:numeric-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#numeric-greater-than-or-equal>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getnumber(A, U),\n getnumber(B, V),\n ( U >= V\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.6.1.1 func:not\n\n'<http://www.w3.org/2007/rif-builtin-function#not>'([A], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( getbool(A, U),\n ( ground(B)\n -> getbool(B, V)\n ; V = B\n ),\n inv(U, V)\n )\n ).\n\n% 4.6.2.1 pred:boolean-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#boolean-equal>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getbool(A, U),\n getbool(B, U)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.6.2.2 pred:boolean-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#boolean-less-than>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getbool(A, false),\n getbool(B, true)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.6.2.3 pred:boolean-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#boolean-greater-than>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getbool(A, true),\n getbool(B, false)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.7.1.1 func:compare @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-function#compare>'([literal(A, B), literal(C, B)], D) :-\n \\+flag(restricted),\n !,\n ( A @< C\n -> D = -1\n ; ( A == C\n -> D = 0\n ; ( A @> C\n -> D = 1\n )\n )\n ).\n\n% 4.7.1.2 func:concat\n\n'<http://www.w3.org/2007/rif-builtin-function#concat>'(A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( findall(F,\n ( member(literal(S, type('<http://www.w3.org/2001/XMLSchema#string>')), A),\n atom_codes(S, F)\n ),\n C\n ),\n flatten(C, D),\n atom_codes(B, D)\n )\n ).\n\n% 4.7.1.3 func:string-join\n\n'<http://www.w3.org/2007/rif-builtin-function#string-join>'([A, literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(B, D),\n findall([D, E],\n ( member(literal(F, type('<http://www.w3.org/2001/XMLSchema#string>')), A),\n atom_codes(F, E)\n ),\n G\n ),\n ( G = [[_, H]|I]\n -> flatten([H|I], J),\n atom_codes(C, J)\n ; C = ''\n )\n )\n ).\n\n% 4.7.1.4 func:substring\n\n'<http://www.w3.org/2007/rif-builtin-function#substring>'([literal(A, _), B, C], literal(D, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n !,\n when(\n ( ground([A, B, C])\n ),\n ( getint(B, I),\n getint(C, J),\n ( I < 1\n -> G is 0,\n H is J+I-1\n ; G is I-1,\n H is J\n ),\n ( H < 0\n -> D = ''\n ; sub_atom(A, G, H, _, D)\n )\n )\n ).\n'<http://www.w3.org/2007/rif-builtin-function#substring>'([literal(A, _), B], literal(D, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( getint(B, I),\n sub_atom(A, 0, E, 0, _),\n J is E-I+1,\n ( I < 1\n -> G is 0,\n H is J+I-1\n ; G is I-1,\n H is J\n ),\n ( H < 0\n -> D = []\n ; sub_atom(A, G, H, _, D)\n )\n )\n ).\n\n% 4.7.1.5 func:string-length\n\n'<http://www.w3.org/2007/rif-builtin-function#string-length>'([literal(A, _)], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( sub_atom(A, 0, B, 0, _)\n )\n ).\n\n% 4.7.1.6 func:upper-case\n\n'<http://www.w3.org/2007/rif-builtin-function#upper-case>'([literal(A, B)], literal(C, B)) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( upcase_atom(A, C)\n )\n ).\n\n% 4.7.1.7 func:lower-case\n\n'<http://www.w3.org/2007/rif-builtin-function#lower-case>'([literal(A, B)], literal(C, B)) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( downcase_atom(A, C)\n )\n ).\n\n% 4.7.1.8 func:encode-for-uri\n\n'<http://www.w3.org/2007/rif-builtin-function#encode-for-uri>'([literal(A, B)], literal(C, B)) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( www_form_encode(A, C)\n )\n ).\n\n% 4.7.1.11 func:substring-before @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-function#substring-before>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sub_atom(A, W, _, _, B),\n sub_atom(A, 0, W, _, C)\n )\n ).\n\n% 4.7.1.12 func:substring-after @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-function#substring-after>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sub_atom(A, _, _, W, B),\n sub_atom(A, _, W, 0, C)\n )\n ).\n\n% 4.7.2.1 pred:contains @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-predicate#contains>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sub_atom(B, 0, D, 0, _),\n sub_atom(A, _, D, _, B)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.7.2.2 pred:starts-with @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-predicate#starts-with>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sub_atom(A, 0, _, _, B)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.7.2.3 pred:ends-with @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-predicate#ends-with>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( sub_atom(A, _, _, 0, B)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.7.2.4 pred:matches @@partial implementation: no flags\n\n'<http://www.w3.org/2007/rif-builtin-predicate#matches>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( regex(B, A, _)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.8.1.1 func:year-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#year-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(C, _, _, _, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.2 func:month-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#month-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, C, _, _, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.3 func:day-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#day-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, _, C, _, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.4 func:hours-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#hours-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, _, _, C, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.5 func:minutes-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#minutes-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, _, _, _, C, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.6 func:seconds-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#seconds-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, _, _, _, _, C, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.7 func:year-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#year-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n date(C, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.8 func:month-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#month-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n date(_, C, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.9 func:day-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#day-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n date(_, _, C, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.10 func:hours-from-time\n\n'<http://www.w3.org/2007/rif-builtin-function#hours-from-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n time(C, _, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.11 func:minutes-from-time\n\n'<http://www.w3.org/2007/rif-builtin-function#minutes-from-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n time(_, C, _, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.12 func:seconds-from-time\n\n'<http://www.w3.org/2007/rif-builtin-function#seconds-from-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n time(_, _, C, _, U, []),\n ( nonvar(B)\n -> C =:= B\n ; C = B\n )\n )\n ).\n\n% 4.8.1.13 func:years-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#years-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], 0) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#years-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n yearmonthduration(C, U, []),\n D is C//12,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.14 func:months-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#months-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], 0) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#months-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n yearmonthduration(C, U, []),\n D is C-(C//12)*12,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.15 func:days-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#days-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], _) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#days-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n daytimeduration(C, U, []),\n D is integer(C)//86400,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.16 func:hours-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#hours-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], _) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#hours-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n daytimeduration(C, U, []),\n D is (integer(C)-(integer(C)//86400)*86400)//3600,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.17 func:minutes-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#minutes-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], _) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#minutes-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n daytimeduration(C, U, []),\n D is (integer(C)-(integer(C)//3600)*3600)//60,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.18 func:seconds-from-duration\n\n'<http://www.w3.org/2007/rif-builtin-function#seconds-from-duration>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], _) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#seconds-from-duration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], B) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n daytimeduration(C, U, []),\n D is C-(integer(C)//60)*60,\n ( nonvar(B)\n -> D =:= B\n ; D = B\n )\n )\n ).\n\n% 4.8.1.19 func:timezone-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#timezone-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n datetime(_, _, _, _, _, _, C, U, []),\n ( ground(B)\n -> atom_codes(B, V),\n daytimeduration(D, V, []),\n D =:= C\n ; daytimeduration(C, E),\n atom_codes(B, E)\n )\n )\n ).\n\n% 4.8.1.20 func:timezone-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#timezone-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>'))], literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n date(_, _, _, C, U, []),\n ( ground(B)\n -> atom_codes(B, V),\n daytimeduration(D, V, []),\n D =:= C\n ; daytimeduration(C, E),\n atom_codes(B, E)\n )\n )\n ).\n\n% 4.8.1.21 func:timezone-from-time\n\n'<http://www.w3.org/2007/rif-builtin-function#timezone-from-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>'))], literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground(A)\n ),\n ( atom_codes(A, U),\n time(_, _, _, C, U, []),\n ( ground(B)\n -> atom_codes(B, V),\n daytimeduration(D, V, []),\n D =:= C\n ; daytimeduration(C, E),\n atom_codes(B, E)\n )\n )\n ).\n\n% 4.8.1.22 func:subtract-dateTimes\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dateTimes>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n F is D-E,\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.23 func:subtract-dates\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dates>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n F is D-E,\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.24 func:subtract-times\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-times>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n F is D-E,\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.25 func:add-yearMonthDurations\n\n'<http://www.w3.org/2007/rif-builtin-function#add-yearMonthDurations>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n F is D+E,\n ( ground(C)\n -> atom_codes(C, W),\n yearmonthduration(G, W, []),\n G =:= F\n ; yearmonthduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.26 func:subtract-yearMonthDurations\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-yearMonthDurations>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n F is D-E,\n ( ground(C)\n -> atom_codes(C, W),\n yearmonthduration(G, W, []),\n G =:= F\n ; yearmonthduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.27 func:multiply-yearMonthDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#multiply-yearMonthDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), B], literal(C, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n yearmonthduration(D, U, []),\n getnumber(B, E),\n F is integer(round(D*E-1)+1),\n ( ground(C)\n -> atom_codes(C, W),\n yearmonthduration(G, W, []),\n G =:= F\n ; yearmonthduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.28 func:divide-yearMonthDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#divide-yearMonthDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), B], literal(C, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n yearmonthduration(D, U, []),\n getnumber(B, E),\n F is integer(round(D/E-1)+1),\n ( ground(C)\n -> atom_codes(C, W),\n yearmonthduration(G, W, []),\n G =:= F\n ; yearmonthduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.29 func:divide-yearMonthDuration-by-yearMonthDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#divide-yearMonthDuration-by-yearMonthDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n F is D/E,\n ( ground(C)\n -> C =:= F\n ; C = F\n )\n )\n ).\n\n% 4.8.1.30 func:add-dayTimeDurations\n\n'<http://www.w3.org/2007/rif-builtin-function#add-dayTimeDurations>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n F is D+E,\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.31 func:subtract-dayTimeDurations\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dayTimeDurations>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n F is D-E,\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.32 func:multiply-dayTimeDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#multiply-dayTimeDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), B], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n daytimeduration(D, U, []),\n getnumber(B, E),\n F is integer(round(D*E-1)+1),\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.33 func:divide-dayTimeDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#divide-dayTimeDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), B], literal(C, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n daytimeduration(D, U, []),\n getnumber(B, E),\n F is integer(round(D/E-1)+1),\n ( ground(C)\n -> atom_codes(C, W),\n daytimeduration(G, W, []),\n G =:= F\n ; daytimeduration(F, H),\n atom_codes(C, H)\n )\n )\n ).\n\n% 4.8.1.34 func:divide-dayTimeDuration-by-dayTimeDuration\n\n'<http://www.w3.org/2007/rif-builtin-function#divide-dayTimeDuration-by-dayTimeDuration>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n F is D/E,\n ( ground(C)\n -> C =:= F\n ; C = F\n )\n )\n ).\n\n% 4.8.1.35 func:add-yearMonthDuration-to-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#add-yearMonthDuration-to-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, E, F, G, H, I, J, U, []),\n yearmonthduration(K, V, []),\n L is E+K-1,\n Q is D+integer(floor(L/12)),\n R is L-integer(floor(L/12))*12+1,\n memotime(datime(Q, R, F, G, H, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is M+I+31536000-N-J,\n ( ground(C)\n -> atom_codes(C, W),\n datetime(P, W, []),\n O =:= P\n ; Offset is -J,\n stamp_date_time(O, date(Year, Month, Day, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n datetime(Year, Month, Day, Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.36 func:add-yearMonthDuration-to-date\n\n'<http://www.w3.org/2007/rif-builtin-function#add-yearMonthDuration-to-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#date>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, E, F, G, U, []),\n yearmonthduration(K, V, []),\n L is E+K-1,\n Q is D+integer(floor(L/12)),\n R is L-integer(floor(L/12))*12+1,\n memotime(datime(Q, R, F, 0, 0, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is (integer(floor(M+31536000-N-G))//60)*60,\n ( ground(C)\n -> atom_codes(C, W),\n date(P, W, []),\n O =:= P\n ; date(O, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.37 func:add-dayTimeDuration-to-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#add-dayTimeDuration-to-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, E, F, G, H, I, J, U, []),\n daytimeduration(K, V, []),\n L is I+K,\n memotime(datime(D, E, F, G, H, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is M+L+31536000-N-J,\n ( ground(C)\n -> atom_codes(C, W),\n datetime(P, W, []),\n O =:= P\n ; Offset is -J,\n stamp_date_time(O, date(Year, Month, Day, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n datetime(Year, Month, Day, Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.38 func:add-dayTimeDuration-to-date\n\n'<http://www.w3.org/2007/rif-builtin-function#add-dayTimeDuration-to-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#date>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, E, F, G, U, []),\n daytimeduration(K, V, []),\n L is integer(K),\n memotime(datime(D, E, F, 0, 0, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is (integer(floor(M+L+31536000-N))//86400)*86400-G,\n ( ground(C)\n -> atom_codes(C, W),\n date(P, W, []),\n O =:= P\n ; date(O, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.39 func:add-dayTimeDuration-to-time\n\n'<http://www.w3.org/2007/rif-builtin-function#add-dayTimeDuration-to-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#time>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, E, F, G, U, []),\n daytimeduration(K, V, []),\n L is F+K,\n memotime(datime(1972, 12, 31, D, E, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n Z is M+L+31536000-N-G,\n O is Z-86400*integer(floor(Z/86400)),\n ( ground(C)\n -> atom_codes(C, W),\n time(P, W, []),\n O =:= P-86400*integer(floor(P/86400))\n ; Offset is -G,\n stamp_date_time(O, date(_, _, _, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n time(Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.40 func:subtract-yearMonthDuration-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-yearMonthDuration-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, E, F, G, H, I, J, U, []),\n yearmonthduration(K, V, []),\n L is E-K-1,\n Q is D+integer(floor(L/12)),\n R is L-integer(floor(L/12))*12+1,\n memotime(datime(Q, R, F, G, H, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is M+I+31536000-N-J,\n ( ground(C)\n -> atom_codes(C, W),\n datetime(P, W, []),\n O =:= P\n ; Offset is -J,\n stamp_date_time(O, date(Year, Month, Day, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n datetime(Year, Month, Day, Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.41 func:subtract-yearMonthDuration-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-yearMonthDuration-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#date>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, E, F, G, U, []),\n yearmonthduration(K, V, []),\n L is E-K-1,\n Q is D+integer(floor(L/12)),\n R is L-integer(floor(L/12))*12+1,\n memotime(datime(Q, R, F, 0, 0, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is (integer(floor(M+31536000-N-G))//60)*60,\n ( ground(C)\n -> atom_codes(C, W),\n date(P, W, []),\n O =:= P\n ; date(O, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.42 func:subtract-dayTimeDuration-from-dateTime\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dayTimeDuration-from-dateTime>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, E, F, G, H, I, J, U, []),\n daytimeduration(K, V, []),\n L is I-integer(K),\n memotime(datime(D, E, F, G, H, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is M+L+31536000-N-J,\n ( ground(C)\n -> atom_codes(C, W),\n datetime(P, W, []),\n O =:= P\n ; Offset is -J,\n stamp_date_time(O, date(Year, Month, Day, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n datetime(Year, Month, Day, Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.43 func:subtract-dayTimeDuration-from-date\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dayTimeDuration-from-date>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#date>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, E, F, G, U, []),\n daytimeduration(K, V, []),\n L is -integer(K),\n memotime(datime(D, E, F, 0, 0, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n O is (integer(floor(M+L+31536000-N))//86400)*86400-G,\n ( ground(C)\n -> atom_codes(C, W),\n date(P, W, []),\n O =:= P\n ; date(O, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.1.44 func:subtract-dayTimeDuration-from-time\n\n'<http://www.w3.org/2007/rif-builtin-function#subtract-dayTimeDuration-from-time>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], literal(C, type('<http://www.w3.org/2001/XMLSchema#time>'))) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, E, F, G, U, []),\n daytimeduration(K, V, []),\n L is F-K,\n memotime(datime(1972, 12, 31, D, E, 0), M),\n memotime(datime(1971, 1, 1, 0, 0, 0), N),\n Z is M+L+31536000-N-G,\n O is Z-86400*integer(floor(Z/86400)),\n ( ground(C)\n -> atom_codes(C, W),\n time(P, W, []),\n O =:= P-86400*integer(floor(P/86400))\n ; Offset is -G,\n stamp_date_time(O, date(_, _, _, Hour, Minute, Second, _, _, _), Offset),\n fmsec(0, Second, Sec),\n time(Hour, Minute, Sec, Offset, S),\n atom_codes(C, S)\n )\n )\n ).\n\n% 4.8.2.1 pred:dateTime-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D =:= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.2 pred:dateTime-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-less-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D < E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.3 pred:dateTime-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-greater-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D > E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.4 pred:date-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D =:= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.5 pred:date-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-less-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D < E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.6 pred:date-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-greater-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D > E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.7 pred:time-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D =:= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.8 pred:time-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-less-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D < E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.9 pred:time-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-greater-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D > E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.10 pred:duration-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#duration-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#duration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#duration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n duration(D, U, []),\n duration(E, V, []),\n ( D =:= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.11 pred:dayTimeDuration-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dayTimeDuration-less-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n ( D < E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.12 pred:dayTimeDuration-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dayTimeDuration-greater-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n ( D > E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.13 pred:yearMonthDuration-less-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#yearMonthDuration-less-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n ( D < E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.14 pred:yearMonthDuration-greater-than\n\n'<http://www.w3.org/2007/rif-builtin-predicate#yearMonthDuration-greater-than>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n ( D > E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.15 pred:dateTime-not-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-not-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D =\\= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.16 pred:dateTime-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-less-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D =< E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.17 pred:dateTime-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dateTime-greater-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dateTime>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n datetime(D, U, []),\n datetime(E, V, []),\n ( D >= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.18 pred:date-not-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-not-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D =\\= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.19 pred:date-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-less-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D =< E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.20 pred:date-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#date-greater-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#date>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n date(D, U, []),\n date(E, V, []),\n ( D >= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.21 pred:time-not-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-not-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D =\\= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.22 pred:time-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-less-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D =< E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.23 pred:time-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#time-greater-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#time>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n time(D, U, []),\n time(E, V, []),\n ( D >= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.24 pred:duration-not-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#duration-not-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#duration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#duration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n duration(D, U, []),\n duration(E, V, []),\n ( D =\\= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.25 pred:dayTimeDuration-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dayTimeDuration-less-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n ( D =< E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.26 pred:dayTimeDuration-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#dayTimeDuration-greater-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n daytimeduration(D, U, []),\n daytimeduration(E, V, []),\n ( D >= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.27 pred:yearMonthDuration-less-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#yearMonthDuration-less-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n ( D =< E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.8.2.28 pred:yearMonthDuration-greater-than-or-equal\n\n'<http://www.w3.org/2007/rif-builtin-predicate#yearMonthDuration-greater-than-or-equal>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'))], C) :-\n \\+flag(restricted),\n when(\n ( ground([A, B])\n ),\n ( atom_codes(A, U),\n atom_codes(B, V),\n yearmonthduration(D, U, []),\n yearmonthduration(E, V, []),\n ( D >= E\n -> C = true\n ; C = false\n )\n )\n ).\n\n% 4.10.1.1 func:PlainLiteral-from-string-lang\n\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-from-string-lang>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-from-string-lang>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(B, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(A, lang(C))) :-\n \\+flag(restricted),\n downcase_atom(B, C).\n\n% 4.10.1.2 func:string-from-PlainLiteral\n\n'<http://www.w3.org/2007/rif-builtin-function#string-from-PlainLiteral>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#string-from-PlainLiteral>'([literal(A, lang(_))], literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted).\n\n% 4.10.1.3 func:lang-from-PlainLiteral\n\n'<http://www.w3.org/2007/rif-builtin-function#lang-from-PlainLiteral>'([literal(_, type('<http://www.w3.org/2001/XMLSchema#string>'))], literal('', type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted),\n !.\n'<http://www.w3.org/2007/rif-builtin-function#lang-from-PlainLiteral>'([literal(_, lang(A))], literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))) :-\n \\+flag(restricted).\n\n% 4.10.1.4 func:PlainLiteral-compare @@partial implementation: no collation\n\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-compare>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))], D) :-\n \\+flag(restricted),\n !,\n ( A @< C\n -> D = -1\n ; ( A == C\n -> D = 0\n ; ( A @> C\n -> D = 1\n )\n )\n ).\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-compare>'([literal(A, lang(B)), literal(C, lang(B))], D) :-\n \\+flag(restricted),\n ( A @< C\n -> D = -1\n ; ( A == C\n -> D = 0\n ; ( A @> C\n -> D = 1\n )\n )\n ).\n\n% 4.10.1.5 func:PlainLiteral-length\n\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-length>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))], C) :-\n \\+flag(restricted),\n !,\n sub_atom(A, 0, C, 0, _).\n'<http://www.w3.org/2007/rif-builtin-function#PlainLiteral-length>'([literal(A, lang(_))], C) :-\n \\+flag(restricted),\n sub_atom(A, 0, C, 0, _).\n\n% 4.10.2.1 pred:matches-language-range @@partial implementation: no false results\n\n'<http://www.w3.org/2007/rif-builtin-predicate#matches-language-range>'([literal(A, lang(B)), literal(C, type('<http://www.w3.org/2001/XMLSchema#string>'))], true) :-\n \\+flag(restricted),\n A \\= '',\n atom_codes(C, U),\n regexp_wildcard(U, V),\n atom_codes(E, V),\n atomic_list_concat(['^', E], F),\n downcase_atom(F, G),\n downcase_atom(B, H),\n regex(G, H, _).\n\n% 4.11.3.1 pred:is-list\n\n'<http://www.w3.org/2007/rif-builtin-predicate#is-list>'([A], B) :-\n \\+flag(restricted),\n ( is_list(A)\n -> B = true\n ; B = false\n ).\n\n% 4.11.3.2 pred:list-contains\n\n'<http://www.w3.org/2007/rif-builtin-predicate#list-contains>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( member(B, A)\n -> C = true\n ; C = false\n )\n ).\n\n% 4.11.4.1 func:make-list\n\n'<http://www.w3.org/2007/rif-builtin-function#make-list>'(A, A) :-\n \\+flag(restricted).\n\n% 4.11.4.2 func:count\n\n'<http://www.w3.org/2007/rif-builtin-function#count>'([A], B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( length(A, B)\n )\n ).\n\n% 4.11.4.3 func:get\n\n'<http://www.w3.org/2007/rif-builtin-function#get>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n ground(B)\n ),\n ( getnumber(B, U),\n nth0(U, A, C)\n )\n ).\n\n% 4.11.4.4 func:sublist\n\n'<http://www.w3.org/2007/rif-builtin-function#sublist>'([A, B, C], D) :-\n \\+flag(restricted),\n !,\n when(\n ( nonvar(A),\n ground([B, C])\n ),\n ( getint(B, U),\n getint(C, V),\n length(A, W),\n ( U < 0\n -> I is W+U\n ; I is U\n ),\n ( V < 0\n -> J is W+V\n ; J is V\n ),\n append(E, F, A),\n length(E, I),\n append(D, G, F),\n K is J-I,\n ( length(D, K)\n -> true\n ; G = []\n ),\n !\n )\n ).\n'<http://www.w3.org/2007/rif-builtin-function#sublist>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n ground(B)\n ),\n ( getint(B, U),\n length(A, W),\n ( U < 0\n -> I is W+U\n ; I is U\n ),\n append(E, C, A),\n length(E, I),\n !\n )\n ).\n\n% 4.11.4.5 func:append\n\n'<http://www.w3.org/2007/rif-builtin-function#append>'([A|B], C) :-\n \\+flag(restricted),\n append(A, B, C).\n\n% 4.11.4.6 func:concatenate\n\n'<http://www.w3.org/2007/rif-builtin-function#concatenate>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( append(A, B)\n )\n ).\n\n% 4.11.4.7 func:insert-before\n\n'<http://www.w3.org/2007/rif-builtin-function#insert-before>'([A, B, C], D) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n ground([B, C])\n ),\n ( getint(B, U),\n length(A, W),\n ( U < 0\n -> I is W+U\n ; I is U\n ),\n append(G, H, A),\n length(G, I),\n append([G, [C], H], D)\n )\n ).\n\n% 4.11.4.8 func:remove\n\n'<http://www.w3.org/2007/rif-builtin-function#remove>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n ground(B)\n ),\n ( getint(B, U),\n length(A, W),\n ( U < 0\n -> I is W+U\n ; I is U\n ),\n append(G, [_|T], A),\n length(G, I),\n append(G, T, C)\n )\n ).\n\n% 4.11.4.9 func:reverse\n\n'<http://www.w3.org/2007/rif-builtin-function#reverse>'([A], B) :-\n \\+flag(restricted),\n reverse(A, B).\n\n% 4.11.4.10 func:index-of\n\n'<http://www.w3.org/2007/rif-builtin-function#index-of>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( nonvar(A),\n ground(B)\n ),\n ( findall(I,\n ( nth0(I, A, B)\n ),\n C\n )\n )\n ).\n\n% 4.11.4.11 func:union\n\n'<http://www.w3.org/2007/rif-builtin-function#union>'(A, B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( append(A, C),\n distinct(C, B)\n )\n ).\n\n% 4.11.4.12 func:distinct-values\n\n'<http://www.w3.org/2007/rif-builtin-function#distinct-values>'([A], B) :-\n \\+flag(restricted),\n when(\n ( nonvar(A)\n ),\n ( distinct(A, B)\n )\n ).\n\n% 4.11.4.13 func:intersect\n\n'<http://www.w3.org/2007/rif-builtin-function#intersect>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground(A),\n ground(B)\n ),\n ( findall(I,\n ( member(I, A),\n member(I, B)\n ),\n C\n )\n )\n ).\n\n% 4.11.4.14 func:except\n\n'<http://www.w3.org/2007/rif-builtin-function#except>'([A, B], C) :-\n \\+flag(restricted),\n when(\n ( ground(A),\n ground(B)\n ),\n ( findall(I,\n ( member(I, A),\n \\+member(I, B)\n ),\n C\n )\n )\n ).\n\n% Prolog built-ins\n\nprolog_sym(abolish, abolish, rel).\nprolog_sym(abort, abort, rel).\nprolog_sym(abs, abs, func).\nprolog_sym(absolute_file_name, absolute_file_name, rel).\nprolog_sym(acos, acos, func).\nprolog_sym(acosh, acosh, func).\nprolog_sym(acyclic_term, acyclic_term, rel).\nprolog_sym(alarm, alarm, rel).\nprolog_sym(append, append, rel).\nprolog_sym(arg, arg, rel).\nprolog_sym(arithmetic_equal, =:=, rel).\nprolog_sym(arithmetic_greater_than, >, rel).\nprolog_sym(arithmetic_greater_than_or_equal, >=, rel).\nprolog_sym(arithmetic_less_than, <, rel).\nprolog_sym(arithmetic_less_than_or_equal, =<, rel).\nprolog_sym(arithmetic_not_equal, =\\=, rel).\nprolog_sym(asin, asin, func).\nprolog_sym(asinh, asinh, func).\nprolog_sym(assert, assert, rel).\nprolog_sym(asserta, asserta, rel).\nprolog_sym(assertz, assertz, rel).\nprolog_sym(at_end_of_stream, at_end_of_stream, rel).\nprolog_sym(atan, atan, func).\nprolog_sym(atan2, atan2, func).\nprolog_sym(atanh, atanh, func).\nprolog_sym(atom, atom, rel).\nprolog_sym(atom_chars, atom_chars, rel).\nprolog_sym(atom_codes, atom_codes, rel).\nprolog_sym(atom_concat, atom_concat, rel).\nprolog_sym(atom_length, atom_length, rel).\nprolog_sym(atom_number, atom_number, rel).\nprolog_sym(atomic, atomic, rel).\nprolog_sym(atomic_concat, atomic_concat, rel).\nprolog_sym(atomic_list_concat, atomic_list_concat, rel).\nprolog_sym(b_getval, b_getval, rel).\nprolog_sym(b_setval, b_setval, rel).\nprolog_sym(bagof, bagof, rel).\nprolog_sym(between, between, rel).\nprolog_sym(break, break, rel).\nprolog_sym(call, call, rel).\nprolog_sym(call_residue_vars, call_residue_vars, rel).\nprolog_sym(callable, callable, rel).\nprolog_sym(catch, catch, rel).\nprolog_sym(ceiling, ceiling, func).\nprolog_sym(char_code, char_code, rel).\nprolog_sym(char_conversion, char_conversion, rel).\nprolog_sym(char_type, char_type, rel).\nprolog_sym(character_count, character_count, rel).\nprolog_sym(clause, clause, rel).\nprolog_sym(close, close, rel).\nprolog_sym(code_type, code_type, rel).\nprolog_sym(compare, compare, rel).\nprolog_sym(compound, compound, rel).\nprolog_sym(conjunction, ',', rel).\nprolog_sym(consult, consult, rel).\nprolog_sym(copy_term, copy_term, rel).\nprolog_sym(copy_term_nat, copy_term_nat, rel).\nprolog_sym(cos, cos, func).\nprolog_sym(cosh, cosh, func).\nprolog_sym(cputime, cputime, func).\nprolog_sym(create_mutable, create_mutable, rel).\nprolog_sym(create_prolog_flag, create_prolog_flag, rel).\nprolog_sym(current_atom, current_atom, rel).\nprolog_sym(current_char_conversion, current_char_conversion, rel).\nprolog_sym(current_input, current_input, rel).\nprolog_sym(current_key, current_key, rel).\nprolog_sym(current_module, current_module, rel).\nprolog_sym(current_op, current_op, rel).\nprolog_sym(current_output, current_output, rel).\nprolog_sym(current_predicate, current_predicate, rel).\nprolog_sym(current_prolog_flag, current_prolog_flag, rel).\nprolog_sym(cut, !, rel).\nprolog_sym(cyclic_term, cyclic_term, rel).\nprolog_sym(date_time_stamp, date_time_stamp, rel).\nprolog_sym(date_time_value, date_time_value, rel).\nprolog_sym(day_of_the_week, day_of_the_week, rel).\nprolog_sym(delete, delete, rel).\nprolog_sym(dif, dif, rel).\nprolog_sym(discontiguous, discontiguous, rel).\nprolog_sym(disjunction, ;, rel).\nprolog_sym(display, display, rel).\nprolog_sym(div, div, func).\nprolog_sym(duplicate_term, duplicate_term, rel).\nprolog_sym(dynamic, dynamic, rel).\nprolog_sym(e, e, func).\nprolog_sym(ensure_loaded, ensure_loaded, rel).\nprolog_sym(environ, environ, rel).\nprolog_sym(epsilon, epsilon, func).\nprolog_sym(erase, erase, rel).\nprolog_sym(erf, erf, func).\nprolog_sym(erfc, erfc, func).\nprolog_sym(exception, exception, rel).\nprolog_sym(exists, exists, rel).\nprolog_sym(exp, exp, func).\nprolog_sym(fail, fail, rel).\nprolog_sym(false, false, rel).\nprolog_sym(file_base_name, file_base_name, rel).\nprolog_sym(file_name_extension, file_name_extension, rel).\nprolog_sym(findall, findall, rel).\nprolog_sym(flatten, flatten, rel).\nprolog_sym(float, float, rel).\nprolog_sym(float_fractional_part, float_fractional_part, func).\nprolog_sym(float_function, float, func).\nprolog_sym(float_integer_part, float_integer_part, func).\nprolog_sym(floor, floor, func).\nprolog_sym(flush_output, flush_output, rel).\nprolog_sym(forall, forall, rel).\nprolog_sym(format, format, rel).\nprolog_sym(format_time, format_time, rel).\nprolog_sym(freeze, freeze, rel).\nprolog_sym(frozen, frozen, rel).\nprolog_sym(functor, functor, rel).\nprolog_sym(garbage_collect, garbage_collect, rel).\nprolog_sym(garbage_collect_atoms, garbage_collect_atoms, rel).\nprolog_sym(gc, gc, rel).\nprolog_sym(gcd, gcd, func).\nprolog_sym(get, get, rel).\nprolog_sym(get_byte, get_byte, rel).\nprolog_sym(get_char, get_char, rel).\nprolog_sym(get_code, get_code, rel).\nprolog_sym(get_mutable, get_mutable, rel).\nprolog_sym(get_time, get_time, rel).\nprolog_sym(get0, get0, rel).\nprolog_sym(getcwd, getcwd, rel).\nprolog_sym(ground, ground, rel).\nprolog_sym(halt, halt, rel).\nprolog_sym(if, soft_cut, rel).\nprolog_sym(if_then, ->, rel).\nprolog_sym(if_then_else, if_then_else, rel).\nprolog_sym(ignore, ignore, rel).\nprolog_sym(include, include, rel).\nprolog_sym(initialization, initialization, rel).\nprolog_sym(instance, instance, rel).\nprolog_sym(integer, integer, rel).\nprolog_sym(integer_conjunction, /\\, func).\nprolog_sym(integer_disjunction, \\/, func).\nprolog_sym(integer_exclusive_disjunction, xor, func).\nprolog_sym(integer_function, integer, func).\nprolog_sym(integer_left_logical_shift, <<, func).\nprolog_sym(integer_negation, \\, func).\nprolog_sym(integer_power, ^, func).\nprolog_sym(integer_quotient, //, func).\nprolog_sym(integer_right_logical_shift, >>, func).\nprolog_sym(is, is, rel).\nprolog_sym(is_list, is_list, rel).\nprolog_sym(is_stream, is_stream, rel).\nprolog_sym(keysort, keysort, rel).\nprolog_sym(last, last, rel).\nprolog_sym(length, length, rel).\nprolog_sym(lgamma, lgamma, func).\nprolog_sym(line_count, line_count, rel).\nprolog_sym(line_position, line_position, rel).\nprolog_sym(listing, listing, rel).\nprolog_sym(log, log, func).\nprolog_sym(log10, log10, func).\nprolog_sym(lsb, lsb, func).\nprolog_sym(max, max, func).\nprolog_sym(max_list, max_list, rel).\nprolog_sym(member, member, rel).\nprolog_sym(memberchk, memberchk, rel).\nprolog_sym(message_to_string, message_to_string, rel).\nprolog_sym(min, min, func).\nprolog_sym(min_list, min_list, rel).\nprolog_sym(minus, -, func).\nprolog_sym(mod, mod, func).\nprolog_sym(msb, msb, func).\nprolog_sym(multifile, multifile, rel).\nprolog_sym(name, name, rel).\nprolog_sym(nb_current, nb_current, rel).\nprolog_sym(nb_delete, nb_delete, rel).\nprolog_sym(nb_getval, nb_getval, rel).\nprolog_sym(nb_linkarg, nb_linkarg, rel).\nprolog_sym(nb_linkval, nb_linkval, rel).\nprolog_sym(nb_setarg, nb_setarg, rel).\nprolog_sym(nb_setval, nb_setval, rel).\nprolog_sym(nl, nl, rel).\nprolog_sym(nonvar, nonvar, rel).\nprolog_sym(not_provable, \\+, rel).\nprolog_sym(not_unifiable, \\=, rel).\nprolog_sym(nth, nth, rel).\nprolog_sym(nth_clause, nth_clause, rel).\nprolog_sym(nth0, nth0, rel).\nprolog_sym(nth1, nth1, rel).\nprolog_sym(number, number, rel).\nprolog_sym(number_chars, number_chars, rel).\nprolog_sym(number_codes, number_codes, rel).\nprolog_sym(numbervars, numbervars, rel).\nprolog_sym(numlist, numlist, rel).\nprolog_sym(on_signal, on_signal, rel).\nprolog_sym(once, once, rel).\nprolog_sym(op, op, rel).\nprolog_sym(open, open, rel).\nprolog_sym(parse_time, parse_time, rel).\nprolog_sym(peek_byte, peek_byte, rel).\nprolog_sym(peek_char, peek_char, rel).\nprolog_sym(peek_code, peek_code, rel).\nprolog_sym(permutation, permutation, rel).\nprolog_sym(pi, pi, func).\nprolog_sym(plus, +, rel).\nprolog_sym(plus_function, +, func).\nprolog_sym(popcount, popcount, func).\nprolog_sym(portray_clause, portray_clause, rel).\nprolog_sym(power, **, func).\nprolog_sym(predicate_property, predicate_property, rel).\nprolog_sym(predsort, predsort, rel).\nprolog_sym(print, print, rel).\nprolog_sym(print_message, print_message, rel).\nprolog_sym(print_message_lines, print_message_lines, rel).\nprolog_sym(product, *, func).\nprolog_sym(prolog_flag, prolog_flag, rel).\nprolog_sym(prolog_load_context, prolog_load_context, rel).\nprolog_sym(prompt, prompt, rel).\nprolog_sym(put, put, rel).\nprolog_sym(put_byte, put_byte, rel).\nprolog_sym(put_char, put_char, rel).\nprolog_sym(put_code, put_code, rel).\nprolog_sym(quotient, /, func).\nprolog_sym(random, random, func).\nprolog_sym(random_float, random_float, func).\nprolog_sym(rational, rational, rel).\nprolog_sym(rational_function, rational, func).\nprolog_sym(rationalize, rationalize, func).\nprolog_sym(read, read, rel).\nprolog_sym(read_term, read_term, rel).\nprolog_sym(recorda, recorda, rel).\nprolog_sym(recorded, recorded, rel).\nprolog_sym(recordz, recordz, rel).\nprolog_sym(rem, rem, func).\nprolog_sym(rename_file, rename_file, rel).\nprolog_sym(repeat, repeat, rel).\nprolog_sym(retract, retract, rel).\nprolog_sym(retractall, retractall, rel).\nprolog_sym(reverse, reverse, rel).\nprolog_sym(round, round, func).\nprolog_sym(same_length, same_length, rel).\nprolog_sym(see, see, rel).\nprolog_sym(seeing, seeing, rel).\nprolog_sym(seen, seen, rel).\nprolog_sym(select, select, rel).\nprolog_sym(selectchk, selectchk, rel).\nprolog_sym(set_input, set_input, rel).\nprolog_sym(set_output, set_output, rel).\nprolog_sym(set_prolog_flag, set_prolog_flag, rel).\nprolog_sym(set_stream_position, set_stream_position, rel).\nprolog_sym(setarg, setarg, rel).\nprolog_sym(setof, setof, rel).\nprolog_sym(set_random, set_random, rel).\nprolog_sym(shell, shell, rel).\nprolog_sym(sign, sign, func).\nprolog_sym(simple, simple, rel).\nprolog_sym(sin, sin, func).\nprolog_sym(sinh, sinh, func).\nprolog_sym(skip, skip, rel).\nprolog_sym(sort, sort, rel).\nprolog_sym(source_file, source_file, rel).\nprolog_sym(source_location, source_location, rel).\nprolog_sym(sqrt, sqrt, func).\nprolog_sym(stamp_date_time, stamp_date_time, rel).\nprolog_sym(statistics, statistics, rel).\nprolog_sym(stream_position, stream_position, rel).\nprolog_sym(stream_position_data, stream_position_data, rel).\nprolog_sym(stream_property, stream_property, rel).\nprolog_sym(sub_atom, sub_atom, rel).\nprolog_sym(sublist, sublist, rel).\nprolog_sym(subsumes_term, subsumes_term, rel).\nprolog_sym(succ, succ, rel).\nprolog_sym(sum_list, sum_list, rel).\nprolog_sym(tab, tab, rel).\nprolog_sym(tan, tan, func).\nprolog_sym(tanh, tanh, func).\nprolog_sym(tell, tell, rel).\nprolog_sym(telling, telling, rel).\nprolog_sym(term_greater_than, @>, rel).\nprolog_sym(term_greater_than_or_equal, @>=, rel).\nprolog_sym(term_hash, term_index, rel).\nprolog_sym(term_identical, ==, rel).\nprolog_sym(term_less_than, @<, rel).\nprolog_sym(term_less_than_or_equal, @=<, rel).\nprolog_sym(term_not_identical, \\==, rel).\nprolog_sym(term_to_atom, term_to_atom, rel).\nprolog_sym(term_variables, term_variables, rel).\nprolog_sym(throw, throw, rel).\nprolog_sym(time, time, rel).\nprolog_sym(time_file, time_file, rel).\nprolog_sym(told, told, rel).\nprolog_sym(true, true, rel).\nprolog_sym(truncate, truncate, func).\nprolog_sym(unifiable, unifiable, rel).\nprolog_sym(unify, =, rel).\nprolog_sym(unify_with_occurs_check, unify_with_occurs_check, rel).\nprolog_sym(univ, =.., rel).\nprolog_sym(unknown, unknown, rel).\nprolog_sym(update_mutable, update_mutable, rel).\nprolog_sym(use_module, use_module, rel).\nprolog_sym(var, var, rel).\nprolog_sym(variant, variant, rel).\nprolog_sym(version, version, rel).\nprolog_sym(when, when, rel).\nprolog_sym(with_output_to, with_output_to, rel).\nprolog_sym(write, write, rel).\nprolog_sym(write_canonical, write_canonical, rel).\nprolog_sym(write_term, write_term, rel).\nprolog_sym(writeln, writeln, rel).\nprolog_sym(writeq, writeq, rel).\n\n%\n% Support\n%\n\ndef_pfx('math:', '<http://www.w3.org/2000/10/swap/math#>').\ndef_pfx('e:', '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#>').\ndef_pfx('list:', '<http://www.w3.org/2000/10/swap/list#>').\ndef_pfx('xsd:', '<http://www.w3.org/2001/XMLSchema#>').\ndef_pfx('log:', '<http://www.w3.org/2000/10/swap/log#>').\ndef_pfx('r:', '<http://www.w3.org/2000/10/swap/reason#>').\ndef_pfx('rdfs:', '<http://www.w3.org/2000/01/rdf-schema#>').\ndef_pfx('time:', '<http://www.w3.org/2000/10/swap/time#>').\ndef_pfx('rdf:', '<http://www.w3.org/1999/02/22-rdf-syntax-ns#>').\ndef_pfx('string:', '<http://www.w3.org/2000/10/swap/string#>').\ndef_pfx('owl:', '<http://www.w3.org/2002/07/owl#>').\ndef_pfx('n3:', '<http://www.w3.org/2004/06/rei#>').\n\nput_pfx(_, URI) :-\n atomic_list_concat(['<', URI, '>'], U),\n pfx(_, U),\n !.\nput_pfx(_, URI) :-\n atomic_list_concat(['<', URI, '>'], U),\n def_pfx(Pf, U),\n \\+pfx(Pf, _),\n !,\n assertz(pfx(Pf, U)).\nput_pfx(Pf, URI) :-\n atomic_list_concat(['<', URI, '>'], U),\n fresh_pf(Pf, Pff),\n assertz(pfx(Pff, U)).\n\nfresh_pf(Pf, Pfx) :-\n atom_concat(Pf, ':', Pfx),\n \\+pfx(Pfx, _),\n !.\nfresh_pf(_, Pfx) :-\n gensym(ns, Pfn),\n fresh_pf(Pfn, Pfx).\n\ncnt(A) :-\n nb_getval(A, B),\n C is B+1,\n nb_setval(A, C),\n ( flag('debug-cnt'),\n C mod 10000 =:= 0\n -> format(user_error, '~w = ~w~n', [A, C]),\n flush_output(user_error)\n ; true\n ).\n\ncnt(A, I) :-\n nb_getval(A, B),\n C is B+I,\n nb_setval(A, C),\n ( flag('debug-cnt'),\n C mod 10000 =:= 0\n -> format(user_error, '~w = ~w~n', [A, C]),\n flush_output(user_error)\n ; true\n ).\n\nwithin_scope([A, B]) :-\n ( var(B)\n -> B = 1\n ; true\n ),\n ( B = 0\n -> brake\n ; nb_getval(limit, C),\n ( C < B\n -> nb_setval(limit, B)\n ; true\n ),\n span(B)\n ),\n nb_getval(scope, A).\n\ndomain(A, true, B) :-\n !,\n findall('<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>'(C, _),\n ( member(C, A)\n ),\n D\n ),\n conj_list(B, D).\ndomain(_, B, B).\n\nexopred(P, S, O) :-\n ( var(P),\n var(S),\n var(O)\n -> pred(P),\n H =.. [P, S, O],\n clause(H, true)\n ; ( var(P)\n -> pred(P)\n ; atom(P),\n current_predicate(P/2)\n ),\n call(P, S, O)\n ).\n\nexogen :-\n forall(\n ( clause(exopred(P, S, O), Body),\n ( nonvar(S)\n ; nonvar(O)\n )\n ),\n ( ( var(P)\n -> pred(P)\n ; atom(P),\n current_predicate(P/2)\n ),\n Head =.. [P, S, O],\n ( \\+clause(Head, Body)\n -> assertz(Head :- Body)\n ; true\n )\n )\n ).\nexogen :-\n \\+flag('multi-query').\n\nucall(A) :-\n ( A = (B, C)\n -> vcall(B),\n ucall(C)\n ; vcall(A)\n ).\n\nvcall(A) :-\n ( ( A =.. [_, V, W]\n ; A = exopred(_, V, W)\n ),\n ( is_gl(V)\n ; is_gl(W)\n )\n -> unify(A, B)\n ; B = A\n ),\n ( B =.. [C, D, E],\n pred(C),\n ( is_gl(D)\n ; is_gl(E)\n )\n -> G =.. [C, H, I],\n call(G),\n unify(H, D),\n unify(I, E)\n ; call(B)\n ).\n\nis_gl(A) :-\n nonvar(A),\n \\+is_list(A),\n ( A = (_, _),\n !\n ; A =.. [F, _, _],\n F \\= literal,\n F \\= rdiv,\n !\n ; A = exopred(_, _, _)\n ).\n\nunify(A, true) :-\n \\+flag('no-erase'),\n nonvar(A),\n A = '<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(X, Y),\n nonvar(Y),\n labelvars(X, 0, _),\n catch(call(Y), _, fail).\nunify(A, B) :-\n \\+flag('no-erase'),\n nonvar(A),\n A = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(X, Y),\n conj_list(Y, C),\n length(C, D),\n D > 1,\n ndsplit(C, E, F),\n E \\= [],\n F \\= [],\n conj_list(G, F),\n ( catch(call(G), _, fail)\n -> conj_list(H, E),\n B = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(X, H)\n ; ( G = '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, I)\n -> catch(call(I), _, fail)\n ; '<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, G)\n ),\n B = true\n ).\nunify(A, B) :-\n nonvar(A),\n A = exopred(P, S, O),\n ( ( nonvar(B)\n ; nonvar(P)\n )\n -> ( nonvar(P)\n -> atom(P)\n ; true\n ),\n B =.. [P, T, R],\n atom(P),\n unify(S, T),\n unify(O, R)\n ; B = exopred(P, T, R),\n unify(S, T),\n unify(O, R)\n ),\n !.\nunify(A, B) :-\n nonvar(B),\n B = exopred(P, S, O),\n ( ( nonvar(A)\n ; nonvar(P)\n )\n -> ( nonvar(P)\n -> atom(P)\n ; true\n ),\n A =.. [P, T, R],\n atom(P),\n unify(S, T),\n unify(O, R)\n ; A = exopred(P, T, R),\n unify(S, T),\n unify(O, R)\n ),\n !.\nunify(A, B) :-\n is_list(A),\n !,\n getlist(B, C),\n C = A.\nunify(A, B) :-\n is_list(B),\n !,\n getlist(A, C),\n C = B.\nunify(A, B) :-\n nonvar(A),\n nonvar(B),\n ( A = (_, _)\n ; B = (_, _)\n ),\n !,\n conj_list(A, C),\n conj_list(B, D),\n includes(C, D),\n includes(D, C).\nunify(A, B) :-\n nonvar(A),\n nonvar(B),\n A =.. [P, S, O],\n B =.. [P, T, R],\n !,\n unify(S, T),\n unify(O, R).\nunify(A, A).\n\nconj_list(true, []) :-\n !.\nconj_list(A, [A]) :-\n A \\= (_, _),\n A \\= false,\n !.\nconj_list((A, B), [A|C]) :-\n conj_list(B, C).\n\nconj_append(A, true, A) :-\n !.\nconj_append((A, B), C, (A, D)) :-\n conj_append(B, C, D),\n !.\nconj_append(A, B, (A, B)).\n\ncflat([], []).\ncflat([A|B], C) :-\n cflat(B, D),\n copy_term_nat(A, E),\n ( E = (_, _),\n conj_list(E, F)\n -> append(F, D, C)\n ; ( E = true\n -> C = D\n ; C = [E|D]\n )\n ).\n\ncouple([], [], []).\ncouple([A|B], [C|D], [[A, C]|E]) :-\n couple(B, D, E).\n\nincludes(_, []) :-\n !.\nincludes(X, [Y|Z]) :-\n member(U, X),\n unify(U, Y),\n includes(X, Z).\n\nconjoin([X], X) :-\n !.\nconjoin([true|Y], Z) :-\n conjoin(Y, Z),\n !.\nconjoin([X|Y], Z) :-\n conjoin(Y, U),\n conj_append(X, U, V),\n ( ground(V)\n -> conj_list(V, A),\n sort(A, B),\n conj_list(Z, B)\n ; Z = V\n ).\n\ndifference([true, _], true) :-\n !.\ndifference([X, true], X) :-\n !.\ndifference([X, Y], Z) :-\n conj_list(X, U),\n conj_list(Y, V),\n difference(U, V, W),\n distinct(W, J),\n conj_list(Z, J).\n\ndifference([], _, []) :-\n !.\ndifference([X|Y], U, V) :-\n member(Z, U),\n unify(X, Z),\n !,\n difference(Y, U, V).\ndifference([X|Y], U, [X|V]) :-\n difference(Y, U, V).\n\nintersect([X], X) :-\n !.\nintersect([true|_], true) :-\n !.\nintersect([X|Y], Z) :-\n intersect(Y, I),\n conj_list(X, U),\n conj_list(I, V),\n intersect(U, V, W),\n distinct(W, J),\n conj_list(Z, J),\n !.\n\nintersect([], _, []) :-\n !.\nintersect([X|Y], U, V) :-\n member(Z, U),\n unify(X, Z),\n V = [X|W],\n intersect(Y, U, W).\nintersect([_|Y], U, V) :-\n intersect(Y, U, V).\n\ncartesian([], []).\ncartesian([A|B], [C|D]) :-\n member(C, A),\n cartesian(B, D).\n\ndistinct(A, B) :-\n ( ground(A)\n -> distinct_hash(A, B)\n ; distinct_value(A, B)\n ).\n\ndistinct_hash([], []) :-\n ( retract(hash_value(_, _)),\n fail\n ; true\n ),\n !.\ndistinct_hash([A|B], C) :-\n term_index(A, D),\n ( hash_value(D, E)\n -> ( unify(A, E)\n -> C = F\n ; C = [A|F]\n )\n ; assertz(hash_value(D, A)),\n C = [A|F]\n ),\n distinct_hash(B, F).\n\ndistinct_value([], []).\ndistinct_value([A|B], [A|D]) :-\n nonvar(A),\n !,\n del(B, A, E),\n distinct_value(E, D).\ndistinct_value([_|A], B) :-\n distinct_value(A, B).\n\ndel([], _, []).\ndel([A|B], C, D) :-\n copy_term_nat(A, Ac),\n copy_term_nat(C, Cc),\n unify(Ac, Cc),\n !,\n del(B, C, D).\ndel([A|B], C, [A|D]) :-\n del(B, C, D).\n\nsubst(_, [], []).\nsubst(A, B, C) :-\n member([D, E], A),\n append(D, F, B),\n !,\n append(E, G, C),\n subst(A, F, G).\nsubst(A, [B|C], [B|D]) :-\n subst(A, C, D).\n\nreplace([], [], X, X) :-\n !.\nreplace([Search|SearchRest], [Replace|ReplaceRest], X, Y) :-\n atomic_list_concat(['(', Search, ')'], Scap),\n scrape(X, Scap, Scrape),\n atom_codes(Replace, RC),\n srlist(Scrape, RC, Subst),\n atom_codes(X, XC),\n subst(Subst, XC, ZC),\n atom_codes(Z, ZC),\n replace(SearchRest, ReplaceRest, Z, Y).\n\nscrape(X, Y, [V|Z]) :-\n regex(Y, X, [W|_]),\n !,\n atom_string(V, W),\n sub_atom(X, _, _, I, V),\n sub_atom(X, _, I, 0, U),\n scrape(U, Y, Z).\nscrape(_, _, []).\n\nsrlist([], _, []).\nsrlist([A|B], C, [[E,C]|D]) :-\n string_codes(A, E),\n srlist(B, C, D).\n\nquicksort([], []).\nquicksort([A|B], C) :-\n split(A, B, D, E),\n quicksort(D, F),\n quicksort(E, G),\n append(F, [A|G], C).\n\nsplit(_, [], [], []).\nsplit(A, [B|C], [B|D], E) :-\n sort([A, B], [B, A]),\n !,\n split(A, C, D, E).\nsplit(A, [B|C], D, [B|E]) :-\n split(A, C, D, E).\n\ndsplit([], [], []).\ndsplit([A|B], [A|C], D):-\n dsplit(B, C, D).\ndsplit([A|B], C, [A|D]):-\n predicate_property(A, dynamic),\n dsplit(B, C, D).\n\nndsplit([], [], []).\nndsplit([A|B], [A|C], D):-\n ndsplit(B, C, D).\nndsplit([A|B], C, [A|D]):-\n ndsplit(B, C, D).\n\nlast_tail([], []) :-\n !.\nlast_tail([_|B], B) :-\n \\+is_list(B),\n !.\nlast_tail([_|B], C) :-\n last_tail(B, C).\n\nsub_list(A, A) :-\n !.\nsub_list([A|B], C) :-\n sub_list(B, A, C).\n\nsub_list(A, _, A) :-\n !.\nsub_list([A|B], C, [C|D]) :-\n !,\n sub_list(B, A, D).\nsub_list([A|B], _, C) :-\n sub_list(B, A, C).\n\ne_transpose([], []).\ne_transpose([A|B], C) :-\n e_transpose(A, [A|B], C).\n\ne_transpose([], _, []).\ne_transpose([_|A], B, [C|D]) :-\n lists_fr(B, C, E),\n e_transpose(A, E, D).\n\nlists_fr([], [], []).\nlists_fr([[A|B]|C], [A|D], [B|E]) :-\n lists_fr(C, D, E).\n\nsum([], 0) :-\n !.\nsum([A|B], C) :-\n getnumber(A, X),\n sum(B, D),\n C is X+D.\n\nproduct([], 1) :-\n !.\nproduct([A|B], C) :-\n getnumber(A, X),\n product(B, D),\n C is X*D.\n\navg(A, B) :-\n sum(A, As),\n length(A, An),\n B is As/An.\n\ncov([A, B], C) :-\n avg(A, Am),\n avg(B, Bm),\n cov1(A, B, Am, Bm, Cp),\n length(A, An),\n C is Cp/(An-1).\n\ncov1([], [], _, _, 0).\ncov1([A|B], [C|D], E, F, G) :-\n cov1(B, D, E, F, H),\n getnumber(A, I),\n getnumber(C, J),\n G is (I-E)*(J-F)+H.\n\npcc([A, B], C) :-\n avg(A, Am),\n avg(B, Bm),\n cov1(A, B, Am, Bm, Cp),\n std1(A, Am, Ap),\n std1(B, Bm, Bp),\n C is Cp/sqrt(Ap*Bp).\n\nrms(A, B) :-\n rms1(A, Ar),\n length(A, An),\n B is sqrt(Ar/An).\n\nrms1([], 0).\nrms1([A|B], C) :-\n rms1(B, D),\n getnumber(A, E),\n C is E^2+D.\n\nstd(A, B) :-\n avg(A, Am),\n std1(A, Am, As),\n length(A, An),\n B is sqrt(As/(An-1)).\n\nstd1([], _, 0).\nstd1([A|B], C, D) :-\n std1(B, C, E),\n getnumber(A, F),\n D is (F-C)^2+E.\n\nbmax([A|B], C) :-\n bmax(B, A, C).\n\nbmax([], A, A).\nbmax([A|B], C, D) :-\n getnumber(A, X),\n getnumber(C, Y),\n ( X > Y\n -> bmax(B, A, D)\n ; bmax(B, C, D)\n ).\n\nbmin([A|B], C) :-\n bmin(B, A, C).\n\nbmin([], A, A).\nbmin([A|B], C, D) :-\n getnumber(A, X),\n getnumber(C, Y),\n ( X < Y\n -> bmin(B, A, D)\n ; bmin(B, C, D)\n ).\n\ninconsistent(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>')|B]) :-\n memberchk('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>'), B),\n !.\ninconsistent(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>')|B]) :-\n memberchk('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>'), B),\n !.\ninconsistent([_|B]) :-\n inconsistent(B).\n\ninverse('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>'),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>')) :-\n !.\ninverse('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>'),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>')).\n\nbnet :-\n ( '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#conditional>'([A|B], _),\n sort(B, C),\n findall(Y,\n ( '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#conditional>'([A|X], Y),\n sort(X, C)\n ),\n L\n ),\n sum(L, S),\n length(L, N),\n Z is S/N,\n \\+bcnd([A|B], _),\n assertz(bcnd([A|B], Z)),\n inverse(A, D),\n \\+bcnd([D|B], _),\n E is 1-Z,\n assertz(bcnd([D|B], E)),\n fail\n ; bcnd(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, _)|B], _),\n ( \\+bvar(A),\n assertz(bvar(A))\n ; true\n ),\n member('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(C, _), B),\n \\+bref(C, A),\n assertz(bref(C, A)),\n \\+bvar(C),\n assertz(bvar(C)),\n fail\n ; true\n ).\n\nbval('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>').\nbval('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>').\n\nbrel('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, _), '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(B, _)) :-\n bref(A, B),\n !.\nbrel(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(B, _)) :-\n bref(C, B),\n brel(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(C, _)).\n\nbpar([], []) :-\n !.\nbpar(['<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, _)|B], [A|C]) :-\n bpar(B, C).\n\nbget(A, B, 1.0) :-\n memberchk(A, B),\n !.\nbget('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>'), B, 0.0) :-\n memberchk('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>'), B),\n !.\nbget('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#F>'), B, C) :-\n ( memberchk('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>'), B),\n !,\n C is 0.0\n ;\n !,\n bget('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#boolean>'(A, '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#T>'), B, D),\n C is 1-D\n ).\nbget(A, B, C) :-\n ( bgot(A, B, C)\n -> true\n ; ( member(X, B),\n brel(A, X),\n member(G, B),\n findall(_,\n ( member(Z, [A|B]),\n brel(G, Z)\n ),\n []\n ),\n del(B, G, H),\n !,\n bget(G, [A|H], U),\n bget(A, H, V),\n bget(G, H, W),\n ( W < 1e-15\n -> C is 0.5\n ; E is U*V/W,\n bmin([E, 1.0], C)\n )\n ; findall([Z, Y],\n ( bcnd([A|O], P),\n bcon(O, B, Q),\n Z is P*Q,\n bpar(O, Y)\n ),\n L\n ),\n findall(Z,\n ( member([_, Z], L)\n ),\n N\n ),\n distinct(N, I),\n findall(Z,\n ( member(Y, I),\n findall(P,\n ( member([P, Y], L)\n ),\n Q\n ),\n sum(Q, R),\n length(Q, S),\n length(Y, T),\n ( Q = []\n -> Z is 0.0\n ; D is 2**(T-ceiling(log(S)/log(2))),\n ( D < 1\n -> Z is R*D\n ; Z is R\n )\n )\n ),\n J\n ),\n ( J = []\n -> C is 0.0\n ; bmax(J, C)\n )\n ),\n assertz(bgot(A, B, C))\n ).\n\nbcon([], _, 1.0) :-\n !.\nbcon(_, B, 0.5) :-\n inconsistent(B),\n !.\nbcon([A|B], C, D) :-\n bget(A, C, E),\n bcon(B, [A|C], F),\n D is E*F.\n\ntmp_file(A) :-\n ( current_prolog_flag(dialect, swi),\n current_prolog_flag(windows, true),\n current_prolog_flag(pid, B)\n -> atomic_list_concat(['pl_eye_', B, '_'], C)\n ; C = 'eye'\n ),\n tmp_file(C, A).\n\nexec(A, B) :-\n shell(A, B),\n ( B =:= 0\n -> true\n ; throw(exec_error(A))\n ).\n\ngetcwd(A) :-\n working_directory(A, A).\n\n%\n% Modified Base64 for XML identifiers\n%\n\nbase64xml(A, B) :-\n base64(A, C),\n atom_codes(C, D),\n subst([[[0'+], [0'_]], [[0'/], [0':]], [[0'=], []]], D, E),\n atom_codes(B, E).\n\nterm_index(A, B) :-\n term_hash(A, B).\n\nif_then_else(A, B, C) :-\n ( catch(call(A), _, fail)\n -> catch(call(B), _, fail)\n ; catch(call(C), _, fail)\n ).\n\nsoft_cut(A, B, C) :-\n ( catch(call(A), _, fail)\n *-> catch(call(B), _, fail)\n ; catch(call(C), _, fail)\n ).\n\ninv(false, true).\ninv(true, false).\n\n+(A, B, C) :-\n plus(A, B, C).\n\n':-'(A, B) :-\n ( var(A)\n -> cpred(C),\n A =.. [C, _, _]\n ; true\n ),\n ( A = exopred(P, S, O)\n -> Ax =.. [P, S, O]\n ; Ax = A\n ),\n clause(Ax, D),\n ( \\+flag(nope),\n ( D = when(H, I)\n -> conj_append(J, istep(Src, _, _, _), I),\n B = when(H, J)\n ; conj_append(B, istep(Src, _, _, _), D)\n )\n -> term_index(true, Pnd),\n ( \\+prfstep(':-'(Ax, B), true, Pnd, ':-'(Ax, B), _, forward, Src)\n -> assertz(prfstep(':-'(Ax, B), true, Pnd, ':-'(Ax, B), _, forward, Src))\n ; true\n )\n ; D = B\n ).\n\nsub_atom_last(A, B, C, D, E) :-\n sub_atom(A, B, C, D, E),\n F is B+1,\n sub_atom(A, F, _, 0, G),\n ( sub_atom(G, _, C, _, E)\n -> sub_atom_last(G, B, C, D, E)\n ; true\n ).\n\nlookup(A, B, C) :-\n tabl(A, B, C),\n !.\nlookup(A, B, C) :-\n var(A),\n nb_getval(tabl, M),\n N is M+1,\n nb_setval(tabl, N),\n atom_number(I, N),\n atomic_list_concat([B, '_tabl_entry_', I], A),\n assertz(tabl(A, B, C)).\n\nescape_string([], []) :-\n !.\nescape_string([0'\\t|A], [0'\\\\, 0't|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\\b|A], [0'\\\\, 0'b|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\\n|A], [0'\\\\, 0'n|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\\r|A], [0'\\\\, 0'r|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\\f|A], [0'\\\\, 0'f|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\"|A], [0'\\\\, 0'\"|B]) :-\n !,\n escape_string(A, B).\nescape_string([0'\\\\|A], [0'\\\\, 0'\\\\|B]) :-\n !,\n escape_string(A, B).\nescape_string([A|B], [A|C]) :-\n escape_string(B, C).\n\nescape_squote([], []) :-\n !.\nescape_squote([0''|A], [0'\\\\, 0''|B]) :-\n !,\n escape_squote(A, B).\nescape_squote([A|B], [A|C]) :-\n escape_squote(B, C).\n\nescape_unicode([], []) :-\n !.\nescape_unicode([A, B|C], D) :-\n 0xD800 =< A,\n A =< 0xDBFF,\n 0xDC00 =< B,\n B =< 0xDFFF,\n E is 0x10000+(A-0xD800)*0x400+(B-0xDC00),\n ( 0x100000 =< E\n -> with_output_to(codes(F), format('\\\\U00~16R', [E]))\n ; with_output_to(codes(F), format('\\\\U000~16R', [E]))\n ),\n append(F, G, D),\n !,\n escape_unicode(C, G).\nescape_unicode([A|B], [A|C]) :-\n escape_unicode(B, C).\n\nesplit_string([], _, [], []) :-\n !.\nesplit_string([], _, A, [A]) :-\n !.\nesplit_string([A|B], C, [], D) :-\n memberchk(A, C),\n !,\n esplit_string(B, C, [], D).\nesplit_string([A|B], C, D, [D|E]) :-\n memberchk(A, C),\n !,\n esplit_string(B, C, [], E).\nesplit_string([A|B], C, D, E) :-\n append(D, [A], F),\n esplit_string(B, C, F, E).\n\nquant(A, some) :-\n var(A),\n !.\nquant('<http://www.w3.org/2000/10/swap/log#implies>'(_, _), allv) :-\n !.\nquant(':-'(_, _), allv) :-\n !.\nquant(answer('<http://www.w3.org/2000/10/swap/log#implies>', _, _), allv) :-\n !.\nquant(answer(':-', _, _), allv) :-\n !.\nquant(answer('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#tactic>', _, _), allv) :-\n !.\nquant(_, some).\n\nlabelvars(A, B, C) :-\n quant(A, Q),\n labelvars(A, B, C, Q).\n\nlabelvars(A, B, C, D) :-\n var(A),\n !,\n atom_number(E, B),\n atomic_list_concat([D, E], A), % failing when A is an attributed variable\n C is B+1.\nlabelvars(A, B, B, _) :-\n atomic(A),\n !.\nlabelvars('<http://www.w3.org/2000/10/swap/log#implies>'(A, B), C, C, D) :-\n D \\= avar,\n nonvar(A),\n nonvar(B),\n !.\nlabelvars((A, B), C, D, Q) :-\n !,\n labelvars(A, C, E, Q),\n labelvars(B, E, D, Q).\nlabelvars([A|B], C, D, Q) :-\n !,\n labelvars(A, C, E, Q),\n labelvars(B, E, D, Q).\nlabelvars(A, B, C, Q) :-\n nonvar(A),\n functor(A, _, D),\n labelvars(0, D, A, B, C, Q).\n\nlabelvars(A, A, _, B, B, _) :-\n !.\nlabelvars(A, B, C, D, E, Q) :-\n F is A+1,\n arg(F, C, G),\n labelvars(G, D, H, Q),\n labelvars(F, B, C, H, E, Q).\n\nrelabel(A, A) :-\n var(A),\n !,\n nb_getval(wn, W),\n labelvars(A, W, N, allv),\n nb_setval(wn, N).\nrelabel([], []) :-\n !.\nrelabel([A|B], [C|D]) :-\n !,\n relabel(A, C),\n relabel(B, D).\nrelabel(A, B) :-\n atom(A),\n !,\n ( '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#relabel>'(A, B)\n -> labelvars(B, 0, _)\n ; B = A\n ).\nrelabel(A, A) :-\n number(A),\n !.\nrelabel(A, B) :-\n A =.. [C|D],\n relabel(C, E),\n relabel(D, F),\n B =.. [E|F].\n\ndynify(A) :-\n var(A),\n !.\ndynify((A, B)) :-\n !,\n dynify(A),\n dynify(B).\ndynify(implies(A, B, _)) :-\n !,\n dynify(A),\n dynify(B).\ndynify(':-'(A, B)) :-\n !,\n dynify(A),\n dynify(B).\ndynify(answer(A, _, _)) :-\n nonvar(A),\n !,\n ( current_predicate(A/2)\n -> true\n ; dynamic(A/2)\n ).\ndynify('<http://www.w3.org/2000/10/swap/log#onPositiveSurface>'(_, A)) :-\n !,\n dynify(A).\ndynify('<http://www.w3.org/2000/10/swap/log#onNegativeSurface>'(_, A)) :-\n !,\n dynify(A).\ndynify('<http://www.w3.org/2000/10/swap/log#onNeutralSurface>'(_, A)) :-\n !,\n dynify(A).\ndynify('<http://www.w3.org/2000/10/swap/log#onQuerySurface>'(_, A)) :-\n !,\n dynify(A).\ndynify(A) :-\n functor(A, F, N),\n ( current_predicate(F/N)\n -> true\n ; dynamic(F/N)\n ).\n\nconjify((A, B), (C, D)) :-\n !,\n conjify(A, C),\n conjify(B, D).\nconjify('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'([literal(when, type('<http://www.w3.org/2001/XMLSchema#string>')),\n '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], true), C], true), when(D, C)) :-\n !,\n D =.. [A|B].\nconjify('<http://eulersharp.sourceforge.net/2003/03swap/prolog#cut>'([], true), !) :-\n !.\nconjify('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#derive>'([literal(!, type('<http://www.w3.org/2001/XMLSchema#string>'))], true), !) :-\n !.\nconjify(A, A).\n\natomify(A, A) :-\n var(A),\n !.\natomify([A|B], [C|D]) :-\n !,\n atomify(A, C),\n atomify(B, D).\natomify(literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), A) :-\n atom(A),\n !.\natomify(A, A).\n\ncommonvars('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#transaction>'(A, _), B, C) :-\n !,\n commonvars(A, B, C).\ncommonvars(A, B, C) :-\n term_variables(A, D),\n term_variables(B, E),\n copy_term_nat([D, E], [F, G]),\n labelvars([F, G], 0, _),\n findall(H,\n ( member(H, F),\n member(H, G)\n ),\n C\n ).\n\ngetvars(A, B) :-\n findvars(A, C, alpha),\n distinct(C, B).\n\nmakevars(A, B, beta(C)) :-\n !,\n distinct(C, D),\n findvars(D, G, beta),\n ( D \\= G\n -> throw(invalid_graffiti(D, in(A)))\n ; true\n ),\n length(D, E),\n length(F, E),\n makevars(A, B, D, F).\nmakevars(A, B, Z) :-\n findvars(A, C, Z),\n distinct(C, D),\n length(D, E),\n length(F, E),\n makevars(A, B, D, F).\n\nmakevars(A, B, C, D) :-\n atomic(A),\n !,\n ( atom(A),\n nth0(E, C, A)\n -> nth0(E, D, B)\n ; B = A\n ).\nmakevars(A, A, _, _) :-\n var(A),\n !.\nmakevars([], [], _, _) :-\n !.\nmakevars([A|B], [C|D], E, F) :-\n makevars(A, C, E, F),\n makevars(B, D, E, F),\n !.\nmakevars(A, B, E, F) :-\n A =.. C,\n makevars(C, [Dh|Dt], E, F),\n nonvar(Dh),\n B =.. [Dh|Dt].\n\nfindvars(A, B, Z) :-\n atomic(A),\n !,\n ( atom(A),\n findvar(A, Z)\n -> B = [A]\n ; B = []\n ).\nfindvars(A, [], _) :-\n var(A),\n !.\nfindvars([], [], _) :-\n !.\nfindvars([A|B], C, Z) :-\n findvars(A, D, Z),\n findvars(B, E, Z),\n append(D, E, C),\n !.\nfindvars(A, B, Z) :-\n A =.. C,\n findvars(C, B, Z).\n\nshallowvars(A, B, Z) :-\n atomic(A),\n !,\n ( atom(A),\n findvar(A, Z)\n -> B = [A]\n ; B = []\n ).\nshallowvars(A, [], _) :-\n var(A),\n !.\nshallowvars([], [], _) :-\n !.\nshallowvars([A|B], C, Z) :-\n shallowvars(A, D, Z),\n shallowvars(B, E, Z),\n append(D, E, C),\n !.\nshallowvars(_, [], _).\n\nfindvar(A, alpha) :-\n !,\n atom_concat('<http://eyereasoner.github.io/var#', _, A).\nfindvar(A, beta) :-\n !,\n ( sub_atom(A, 0, _, _, '_bn_')\n ; sub_atom(A, 0, _, _, '_e_')\n ; sub_atom(A, _, 19, _, '/.well-known/genid/')\n ; sub_atom(A, 0, _, _, some)\n ; sub_atom(A, 0, _, _, '_:')\n ).\nfindvar(A, delta) :-\n !,\n ( sub_atom(A, _, 19, _, '/.well-known/genid/')\n ; sub_atom(A, 0, _, _, some)\n ).\nfindvar(A, epsilon) :-\n !,\n sub_atom(A, 0, 1, _, '_'),\n \\+ sub_atom(A, 0, _, _, '_bn_'),\n \\+ sub_atom(A, 0, _, _, '_e_').\nfindvar(A, zeta) :-\n sub_atom(A, 0, _, _, some),\n !.\nfindvar(A, eta) :-\n sub_atom(A, 0, _, _, allv).\n\nraw_type(A, '<http://www.w3.org/1999/02/22-rdf-syntax-ns#List>') :-\n is_list(A),\n !.\nraw_type(A, '<http://www.w3.org/2000/10/swap/log#Literal>') :-\n number(A),\n !.\nraw_type(A, '<http://www.w3.org/2000/10/swap/log#Literal>') :-\n atom(A),\n \\+ sub_atom(A, 0, _, _, some),\n \\+ sub_atom(A, 0, _, _, avar),\n \\+ (sub_atom(A, 0, 1, _, '<'), sub_atom(A, _, 1, 0, '>')),\n !.\nraw_type(literal(_, _), '<http://www.w3.org/2000/10/swap/log#Literal>') :-\n !.\nraw_type(rdiv(_, _), '<http://www.w3.org/2000/10/swap/log#Literal>') :-\n !.\nraw_type('<http://eulersharp.sourceforge.net/2003/03swap/log-rules#epsilon>', '<http://www.w3.org/2000/10/swap/log#Literal>') :-\n !.\nraw_type((_, _), '<http://www.w3.org/2000/10/swap/log#Formula>') :-\n !.\nraw_type(set(_), '<http://www.w3.org/2000/10/swap/log#Set>') :-\n !.\nraw_type(A, '<http://www.w3.org/2000/10/swap/log#Formula>') :-\n functor(A, B, C),\n B \\= ':',\n C >= 2,\n !.\nraw_type(_, '<http://www.w3.org/2000/10/swap/log#Other>').\n\ngetnumber(rdiv(A, B), C) :-\n nonvar(A),\n !,\n C is A/B.\ngetnumber(A, A) :-\n number(A),\n !.\ngetnumber(A, epsilon) :-\n nonvar(A),\n A = '<http://eulersharp.sourceforge.net/2003/03swap/log-rules#epsilon>',\n !.\ngetnumber(A, A) :-\n nonvar(A),\n memberchk(A, [inf, -inf, nan]),\n !.\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#dateTime>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n datetime(B, C, []).\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#date>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n date(B, C, []).\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#time>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n time(B, C, []).\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#duration>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n duration(B, C, []).\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#yearMonthDuration>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n yearmonthduration(B, C, []).\ngetnumber(literal(A, type('<http://www.w3.org/2001/XMLSchema#dayTimeDuration>')), B) :-\n !,\n ground(A),\n atom_codes(A, C),\n daytimeduration(B, C, []).\ngetnumber(literal(A, _), B) :-\n ground(A),\n atom_codes(A, C),\n numeral(C, D),\n catch(number_codes(B, D), _, fail).\n\ngetint(A, B) :-\n getnumber(A, C),\n B is integer(round(C)).\n\ngetbool(literal(false, type('<http://www.w3.org/2001/XMLSchema#boolean>')), false).\ngetbool(literal(true, type('<http://www.w3.org/2001/XMLSchema#boolean>')), true).\ngetbool(literal('0', type('<http://www.w3.org/2001/XMLSchema#boolean>')), false).\ngetbool(literal('1', type('<http://www.w3.org/2001/XMLSchema#boolean>')), true).\ngetbool(false, false).\ngetbool(true, true).\n\ngetlist(A, A) :-\n var(A),\n !.\ngetlist(set(A), A) :-\n !.\ngetlist('<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>', []) :-\n !.\ngetlist([], []) :-\n !.\ngetlist([A|B], [C|D]) :-\n getlist(A, C),\n !,\n getlist(B, D).\ngetlist([A|B], [A|D]) :-\n !,\n getlist(B, D).\ngetlist(A, [B|C]) :-\n '<http://www.w3.org/1999/02/22-rdf-syntax-ns#first>'(A, B),\n '<http://www.w3.org/1999/02/22-rdf-syntax-ns#rest>'(A, D),\n getlist(D, C).\n\ngetstring(A, B) :-\n '<http://www.w3.org/2000/10/swap/log#uri>'(A, B),\n !.\ngetstring(A, A).\n\ngetcodes(literal(A, _), B) :-\n nonvar(A),\n !,\n atom_codes(A, B).\ngetcodes(A, B) :-\n nonvar(A),\n with_output_to_chars(wg(A), B).\n\npreformat([], []) :-\n !.\npreformat([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>'))|B], [A|D]) :-\n !,\n preformat(B, D).\npreformat([A|B], [A|D]) :-\n preformat(B, D).\n\nnumeral([0'-, 0'.|A], [0'-, 0'0, 0'.|A]) :-\n !.\nnumeral([0'+, 0'.|A], [0'+, 0'0, 0'.|A]) :-\n !.\nnumeral([0'.|A], [0'0, 0'.|A]) :-\n !.\nnumeral(A, B) :-\n append([C, [0'., 0'e], D], A),\n append([C, [0'., 0'0, 0'e], D], B),\n !.\nnumeral(A, B) :-\n append([C, [0'., 0'E], D], A),\n append([C, [0'., 0'0, 0'E], D], B),\n !.\nnumeral(A, B) :-\n last(A, 0'.),\n append(A, [0'0], B),\n !.\nnumeral(A, A).\n\nrdiv_codes(rdiv(A, B), C) :-\n append(D, [0'.|E], C),\n append(D, E, F),\n number_codes(A, F),\n lzero(E, G),\n number_codes(B, [0'1|G]),\n !.\nrdiv_codes(rdiv(A, 1), C) :-\n number_codes(A, C).\n\nlzero([], []) :-\n !.\nlzero([_|A], [0'0|B]) :-\n lzero(A, B).\n\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), C], B) :-\n nonvar(C),\n '<http://www.w3.org/2000/01/rdf-schema#subClassOf>'(C, '<http://www.w3.org/2001/XMLSchema#integer>'),\n integer(B),\n !,\n atom_number(A, B).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#integer>'], B) :-\n integer(B),\n !,\n atom_number(A, B).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#double>'], B) :-\n float(B),\n !,\n atom_number(A, B).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#dateTime>'], B) :-\n ( number(B)\n -> datetime(B, C)\n ; nonvar(B),\n B = date(Year, Month, Day, Hour, Minute, Second, Offset, _, _),\n datetime(Year, Month, Day, Hour, Minute, Second, Offset, C)\n ),\n !,\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#date>'], B) :-\n ( number(B)\n -> date(B, C)\n ; nonvar(B),\n B = date(Year, Month, Day, _, _, _, Offset, _, _),\n date(Year, Month, Day, Offset, C)\n ),\n !,\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#time>'], B) :-\n ( number(B)\n -> time(B, C)\n ; nonvar(B),\n B = date(_, _, _, Hour, Minute, Second, Offset, _, _),\n time(Hour, Minute, Second, Offset, C)\n ),\n !,\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#duration>'], B) :-\n number(B),\n !,\n daytimeduration(B, C),\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#yearMonthDuration>'], B) :-\n number(B),\n !,\n yearmonthduration(B, C),\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#dayTimeDuration>'], B) :-\n number(B),\n !,\n daytimeduration(B, C),\n atom_codes(A, C).\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/2001/XMLSchema#boolean>'], A) :-\n atomic(A),\n getbool(A, A),\n !.\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), prolog:atom], A) :-\n atomic(A),\n \\+ (sub_atom(A, 0, 1, _, '<'), sub_atom(A, _, 1, 0, '>')),\n !.\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), '<http://www.w3.org/1999/02/22-rdf-syntax-ns#langString>'], literal(A, lang(_))) :-\n !.\ndtlit([literal(A, type('<http://www.w3.org/2001/XMLSchema#string>')), B], literal(A, type(B))).\n\nhash_to_ascii([], L1, L1).\nhash_to_ascii([A|B], [C, D|L3], L4) :-\n E is A>>4 /\\ 15,\n F is A /\\ 15,\n code_type(C, xdigit(E)),\n code_type(D, xdigit(F)),\n hash_to_ascii(B, L3, L4).\n\nmemotime(datime(A, B, C, D, E, F), G) :-\n ( mtime(datime(A, B, C, D, E, F), G)\n -> true\n ; catch(date_time_stamp(date(A, B, C, D, E, F, 0, -, -), H), _, fail),\n fmsec(F, H, G),\n assertz(mtime(datime(A, B, C, D, E, F), G))\n ).\n\ndatetime(A, L1, L13) :-\n int(B, L1, [0'-|L3]),\n int(C, L3, [0'-|L5]),\n int(D, L5, [0'T|L7]),\n int(E, L7, [0':|L9]),\n int(F, L9, [0':|L11]),\n decimal(G, L11, L12),\n timezone(H, L12, L13),\n I is -H,\n catch(date_time_stamp(date(B, C, D, E, F, G, I, -, -), J), _, fail),\n fmsec(G, J, A).\n\ndatetime(A, B, C, D, E, F, G, L1, L13) :-\n int(A, L1, [0'-|L3]),\n int(B, L3, [0'-|L5]),\n int(C, L5, [0'T|L7]),\n int(D, L7, [0':|L9]),\n int(E, L9, [0':|L11]),\n decimal(F, L11, L12),\n timezone(G, L12, L13).\n\ndate(A, L1, L7) :-\n int(B, L1, [0'-|L3]),\n int(C, L3, [0'-|L5]),\n int(D, L5, L6),\n timezone(H, L6, L7),\n I is -H,\n catch(date_time_stamp(date(B, C, D, 0, 0, 0, I, -, -), E), _, fail),\n fmsec(0, E, A).\n\ndate(A, B, C, D, L1, L7) :-\n int(A, L1, [0'-|L3]),\n int(B, L3, [0'-|L5]),\n int(C, L5, L6),\n timezone(D, L6, L7).\n\ntime(A, L1, L7) :-\n int(B, L1, [0':|L3]),\n int(C, L3, [0':|L5]),\n decimal(D, L5, L6),\n timezone(E, L6, L7),\n ( B = 24\n -> A is C*60+D-E\n ; A is B*3600+C*60+D-E\n ).\n\ntime(A, B, C, D, L1, L7) :-\n int(A, L1, [0':|L3]),\n int(B, L3, [0':|L5]),\n decimal(C, L5, L6),\n timezone(D, L6, L7).\n\nduration(A, L1, L7) :-\n dsign(B, L1, [0'P|L3]),\n years(C, L3, L4),\n months(D, L4, L5),\n days(E, L5, L6),\n dtime(F, L6, L7),\n A is B*(C*31556952+D*2629746+E*86400.0+F).\n\nyearmonthduration(A, L1, L5) :-\n dsign(B, L1, [0'P|L3]),\n years(C, L3, L4),\n months(D, L4, L5),\n A is B*(C*12+D).\n\ndaytimeduration(A, L1, L5) :-\n dsign(B, L1, [0'P|L3]),\n days(C, L3, L4),\n dtime(D, L4, L5),\n A is B*(C*86400.0+D).\n\ntimezone(A, L1, L4) :-\n int(B, L1, [0':|L3]),\n !,\n int(C, L3, L4),\n A is B*3600+C*60.\ntimezone(0, [0'Z|L2], L2) :-\n !.\ntimezone(0, L1, L1).\n\ndsign(1, [0'+|L2], L2).\ndsign(-1, [0'-|L2], L2).\ndsign(1, L1, L1).\n\ndtime(A, [0'T|L2], L5) :-\n !,\n hours(B, L2, L3),\n minutes(C, L3, L4),\n seconds(D, L4, L5),\n A is B*3600+C*60+D.\ndtime(0, L1, L1).\n\nyears(A, L1, L3) :-\n int(A, L1, [0'Y|L3]).\nyears(0, L1, L1).\n\nmonths(A, L1, L3) :-\n int(A, L1, [0'M|L3]).\nmonths(0, L1, L1) .\n\ndays(A, L1, L3) :-\n int(A, L1, [0'D|L3]).\ndays(0, L1, L1).\n\nhours(A, L1, L3) :-\n int(A, L1, [0'H|L3]).\nhours(0, L1, L1).\n\nminutes(A, L1, L3) :-\n int(A, L1, [0'M|L3]).\nminutes(0, L1, L1).\n\nseconds(A, L1, L3) :-\n decimal(A, L1, [0'S|L3]).\nseconds(0, L1, L1).\n\nint(A, L1, L4) :-\n sgn(B, L1, L2),\n digit(C, L2, L3),\n digits(D, L3, L4),\n number_codes(A, [B, C|D]).\n\ndecimal(A, L1, L5) :-\n sgn(B, L1, L2),\n digit(C, L2, L3),\n digits(D, L3, L4),\n fraction(E, L4, L5),\n append([B, C|D], E, F),\n number_codes(A, F).\n\nsgn(0'+, [0'+|L2], L2).\nsgn(0'-, [0'-|L2], L2).\nsgn(0'+, L1, L1).\n\nfraction([0'., A|B], [0'.|L2], L4) :-\n !,\n digit(A, L2, L3),\n digits(B, L3, L4).\nfraction([], L1, L1).\n\ndigits([A|B], L1, L3) :-\n digit(A, L1, L2),\n digits(B, L2, L3).\ndigits([], L1, L1).\n\ndigit(A, [A|L2], L2) :-\n code_type(A, digit).\n\nfmsec(A, B, C) :-\n integer(A),\n !,\n C is floor(B).\nfmsec(_, B, B).\n\ndatetime(A, B) :-\n stamp_date_time(A, date(Year, Month, Day, Hour, Minute, Second, _, _, _), 0),\n fmsec(A, Second, Sec),\n ycodes(Year, C),\n ncodes(Month, D),\n ncodes(Day, E),\n ncodes(Hour, F),\n ncodes(Minute, G),\n ncodes(Sec, H),\n append([C, [0'-], D, [0'-], E, [0'T], F, [0':], G, [0':], H, [0'Z]], B).\n\ndatetime(Year, Month, Day, Hour, Minute, Second, Offset, B) :-\n ycodes(Year, C),\n ncodes(Month, D),\n ncodes(Day, E),\n ncodes(Hour, F),\n ncodes(Minute, G),\n ncodes(Second, H),\n ( Offset =:= 0\n -> append([C, [0'-], D, [0'-], E, [0'T], F, [0':], G, [0':], H, [0'Z]], B)\n ; ( Offset > 0\n -> I = [0'-],\n OHour is Offset//3600\n ; I = [0'+],\n OHour is -Offset//3600\n ),\n ncodes(OHour, J),\n OMinute is (Offset mod 3600)//60,\n ncodes(OMinute, K),\n append([C, [0'-], D, [0'-], E, [0'T], F, [0':], G, [0':], H, I, J, [0':], K], B)\n ).\n\ndate(A, B) :-\n N is A+3600*12,\n stamp_date_time(N, date(Year, Month, Day, _, _, _, _, _, _), 0),\n ycodes(Year, C),\n ncodes(Month, D),\n ncodes(Day, E),\n Offset is (round(floor(N)) mod 86400) - 3600*12,\n ( Offset =:= 0\n -> append([C, [0'-], D, [0'-], E, [0'Z]], B)\n ; ( Offset > 0\n -> I = [0'-],\n OHour is Offset//3600\n ; I = [0'+],\n OHour is -Offset//3600\n ),\n ncodes(OHour, J),\n OMinute is (Offset mod 3600)//60,\n ncodes(OMinute, K),\n append([C, [0'-], D, [0'-], E, I, J, [0':], K], B)\n ).\n\ndate(Year, Month, Day, Offset, B) :-\n ycodes(Year, C),\n ncodes(Month, D),\n ncodes(Day, E),\n ( Offset =:= 0\n -> append([C, [0'-], D, [0'-], E, [0'Z]], B)\n ; ( Offset > 0\n -> I = [0'-],\n OHour is Offset//3600\n ; I = [0'+],\n OHour is -Offset//3600\n ),\n ncodes(OHour, J),\n OMinute is (Offset mod 3600)//60,\n ncodes(OMinute, K),\n append([C, [0'-], D, [0'-], E, I, J, [0':], K], B)\n ).\n\ntime(A, B) :-\n stamp_date_time(A, date(_, _, _, Hour, Minute, Second, _, _, _), 0),\n fmsec(A, Second, Sec),\n ncodes(Hour, F),\n ncodes(Minute, G),\n ncodes(Sec, H),\n append([F, [0':], G, [0':], H, [0'Z]], B).\n\ntime(Hour, Minute, Second, Offset, B) :-\n ncodes(Hour, F),\n ncodes(Minute, G),\n ncodes(Second, H),\n ( Offset =:= 0\n -> append([F, [0':], G, [0':], H, [0'Z]], B)\n ; ( Offset > 0\n -> I = [0'-],\n OHour is Offset//3600\n ; I = [0'+],\n OHour is -Offset//3600\n ),\n ncodes(OHour, J),\n OMinute is (Offset mod 3600)//60,\n ncodes(OMinute, K),\n append([F, [0':], G, [0':], H, I, J, [0':], K], B)\n ).\n\nyearmonthduration(A, B) :-\n ( A < 0\n -> C = [0'-]\n ; C = []\n ),\n D is abs(A),\n E is D//12,\n number_codes(E, Years),\n F is D-(D//12)*12,\n number_codes(F, Months),\n append([C, [0'P], Years, [0'Y], Months, [0'M]], B).\n\ndaytimeduration(A, B) :-\n AInt is round(floor(A)),\n AFrac is A-AInt,\n ( AInt < 0\n -> C = [0'-]\n ; C = []\n ),\n D is abs(AInt),\n E is D//86400,\n number_codes(E, Days),\n F is (D-(D//86400)*86400)//3600,\n number_codes(F, Hours),\n G is (D-(D//3600)*3600)//60,\n number_codes(G, Minutes),\n H is D-(D//60)*60+AFrac,\n number_codes(H, Seconds),\n append([C, [0'P| Days], [0'D, 0'T| Hours], [0'H| Minutes], [0'M| Seconds], [0'S]], B).\n\nncodes(A, B) :-\n number_codes(A, D),\n ( A < 10\n -> B = [0'0| D]\n ; B = D\n ).\n\nycodes(A, B) :-\n C is abs(A),\n number_codes(C, D),\n ( C < 10\n -> E = [0'0, 0'0, 0'0| D]\n ; ( C < 100\n -> E = [0'0, 0'0| D]\n ; ( C < 1000\n -> E = [0'0| D]\n ; E = D\n )\n )\n ),\n ( A >= 0\n -> B = E\n ; B = [0'-|E]\n ).\n\nabsolute_uri('-', '-') :-\n !.\nabsolute_uri(A, B) :-\n ( is_absolute_url(A)\n -> B = A\n ; absolute_file_name(A, C),\n prolog_to_os_filename(D, C),\n atom_codes(D, E),\n subst([[[0x20], [0'%, 0'2, 0'0]]], E, F),\n atom_codes(G, F),\n atomic_list_concat(['file://', G], B)\n ).\n\nresolve_uri(A, _, A) :-\n sub_atom(A, _, 1, _, ':'),\n !.\nresolve_uri('', A, A) :-\n !.\nresolve_uri('#', A, B) :-\n !,\n atomic_list_concat([A, '#'], B).\nresolve_uri(A, B, A) :-\n \\+sub_atom(B, _, 1, _, ':'),\n !.\nresolve_uri(A, B, C) :-\n so_uri(U),\n atom_length(U, V),\n sub_atom(A, 0, 1, _, '#'),\n sub_atom(B, 0, V, _, U),\n !,\n atomic_list_concat([B, A], C).\nresolve_uri(A, B, C) :-\n sub_atom(A, 0, 2, _, './'),\n !,\n sub_atom(A, 2, _, 0, R),\n resolve_uri(R, B, C).\nresolve_uri(A, B, C) :-\n sub_atom(A, 0, 3, _, '../'),\n !,\n sub_atom(A, 3, _, 0, R),\n so_uri(U),\n atom_length(U, V),\n sub_atom(B, 0, V, D, U),\n sub_atom(B, V, D, _, E),\n ( sub_atom(E, F, 1, G, '/'),\n sub_atom(E, _, G, 0, H),\n \\+sub_atom(H, _, _, _, '/'),\n K is V+F\n -> sub_atom(B, 0, K, _, S)\n ; S = B\n ),\n resolve_uri(R, S, C).\nresolve_uri(A, B, C) :-\n so_uri(U),\n atom_length(U, V),\n sub_atom(A, 0, 1, _, '/'),\n sub_atom(B, 0, V, D, U),\n sub_atom(B, V, D, _, E),\n ( sub_atom(E, F, 1, _, '/')\n -> sub_atom(E, 0, F, _, G)\n ; G = E\n ),\n !,\n atomic_list_concat([U, G, A], C).\nresolve_uri(A, B, C) :-\n so_uri(U),\n atom_length(U, V),\n sub_atom(B, 0, V, D, U),\n sub_atom(B, V, D, _, E),\n ( sub_atom(E, F, 1, G, '/'),\n sub_atom(E, _, G, 0, H),\n \\+sub_atom(H, _, _, _, '/')\n -> sub_atom(E, 0, F, _, I)\n ; I = E\n ),\n !,\n atomic_list_concat([U, I, '/', A], C).\nresolve_uri(A, _, _) :-\n nb_getval(line_number, Ln),\n throw(unresolvable_relative_uri(A, after_line(Ln))).\n\nso_uri('http://').\nso_uri('https://').\nso_uri('ftp://').\nso_uri('file://').\n\nwcacher(A, B) :-\n wcache(A, B),\n !.\nwcacher(A, B) :-\n wcache(C, D),\n sub_atom(A, 0, I, _, C),\n sub_atom(A, I, _, 0, E),\n atomic_list_concat([D, E], B).\n\nprolog_verb(S, Name) :-\n ( atom(S),\n atom_concat('\\'<http://eulersharp.sourceforge.net/2003/03swap/prolog#', A, S),\n atom_concat(B, '>\\'', A)\n -> ( B = conjunction\n -> Pred = '\\', \\''\n ; ( B = disjunction\n -> Pred = '\\';\\''\n ; ( prolog_sym(B, Pred, _)\n -> true\n ; nb_getval(line_number, Ln),\n throw(invalid_prolog_builtin(B, after_line(Ln)))\n )\n )\n ),\n Name = prolog:Pred\n ; Name = S\n ).\n\ntimestamp(Stamp) :-\n get_time(StampN),\n datetime(StampN, StampC),\n atom_codes(StampA, StampC),\n ( sub_atom(StampA, I, 1, 0, 'Z'),\n I > 23\n -> sub_atom(StampA, 0, 23, _, StampB),\n atomic_list_concat([StampB, 'Z'], Stamp)\n ; Stamp = StampA\n ).\n\n%\n% Regular expressions\n%\n\n% Regular Expressions inspired by http://www.cs.sfu.ca/~cameron/Teaching/384/99-3/regexp-plg.html\nregex(RE_esc_atom, Input_esc_atom, Output_esc_atoms) :-\n atom_codes(RE_esc_atom, RE_esc),\n atom_codes(Input_esc_atom, Input_esc),\n escape_string(RE, RE_esc),\n re(Parsed_RE, RE, []),\n ( RE = [0'^|_]\n -> Bos = true\n ; Bos = false\n ),\n escape_string(Input, Input_esc),\n tokenize2(Parsed_RE, Input, Outputs, Bos),\n findall(Output_esc_atom,\n ( member(Output, Outputs),\n escape_string(Output, Output_esc),\n atom_codes(Output_esc_atom, Output_esc)\n ),\n Output_esc_atoms\n ),\n !.\n\ntokenize2(_P_RE, [], [], true).\ntokenize2(P_RE, Input, Output, Bos) :-\n ( rematch1(P_RE, Input, _, Output)\n -> true\n ; Bos = false,\n Input = [_|Inp],\n tokenize2(P_RE, Inp, Output, Bos)\n ).\n\nrematch1(union(RE1, _RE2), S, U, Selected) :-\n rematch1(RE1, S, U, Selected).\nrematch1(union(_RE1, RE2), S, U, Selected) :-\n rematch1(RE2, S, U, Selected).\nrematch1(conc(RE1, RE2), S, U, Selected) :-\n rematch1(RE1, S, U1, Sel1),\n rematch1(RE2, U1, U, Sel2),\n append(Sel1, Sel2, Selected).\nrematch1(star(RE), S, U, Selected) :-\n rematch1(RE, S, U1, Sel1),\n rematch1(star(RE), U1, U, Sel2),\n append(Sel1, Sel2, Selected).\nrematch1(star(_RE), S, S, []).\nrematch1(qm(RE), S, U, Selected) :-\n rematch1(RE, S, U, Selected).\nrematch1(qm(_RE), S, S, []).\nrematch1(plus(RE), S, U, Selected) :-\n rematch1(RE, S, U1, Sel1),\n rematch1(star(RE), U1, U, Sel2),\n append(Sel1, Sel2, Selected).\nrematch1(group(RE), S, U, Selected) :-\n rematch1(RE, S, U, Sel1),\n append(P, U, S),\n append(Sel1, [P], Selected).\nrematch1(any, [_C1|U], U, []).\nrematch1(char(C), [C|U], U, []).\nrematch1(bos, S, S, []).\nrematch1(eos, [], [], []).\nrematch1(negSet(Set), [C|U], U, []) :-\n \\+charSetMember(C, Set).\nrematch1(posSet(Set), [C|U], U, []) :-\n charSetMember(C, Set).\n\ncharSetMember(C, [char(C)|_]).\ncharSetMember(C, [range(C1, C2)|_]) :-\n C1 =< C,\n C =< C2.\ncharSetMember(C, [negSet(Set)|_]) :-\n \\+charSetMember(C, Set).\ncharSetMember(C, [posSet(Set)|_]) :-\n charSetMember(C, Set).\ncharSetMember(C, [_|T]) :-\n charSetMember(C, T).\n\nre(Z, L1, L3) :-\n basicRE(W, L1, L2),\n reTail(W, Z, L2, L3).\n\nreTail(W, Z, [0'||L2], L4) :-\n basicRE(X, L2, L3),\n reTail(union(W, X), Z, L3, L4).\nreTail(W, W, L1, L1).\n\nbasicRE(Z, L1, L3) :-\n simpleRE(W, L1, L2),\n basicREtail(W, Z, L2, L3).\n\nbasicREtail(W, Z, L1, L3) :-\n simpleRE(X, L1, L2),\n basicREtail(conc(W, X), Z, L2, L3).\nbasicREtail(W, W, L1, L1).\n\nsimpleRE(Z, L1, L3) :-\n elementalRE(W, L1, L2),\n simpleREtail(W, Z, L2, L3).\n\nsimpleREtail(W, star(W), [0'*|L2], L2).\nsimpleREtail(W, qm(W), [0'?|L2], L2).\nsimpleREtail(W, plus(W), [0'+|L2], L2).\nsimpleREtail(W, W, L1, L1).\n\nelementalRE(any, [0'.|L2], L2).\nelementalRE(group(X), [0'(|L2], L4) :-\n re(X, L2, [0')|L4]).\nelementalRE(bos, [0'^|L2], L2).\nelementalRE(eos, [0'$|L2], L2).\nelementalRE(posSet([range(0'A, 0'Z), range(0'a, 0'z), range(0'0, 0'9), char(0'_)]), [0'\\\\, 0'w|L2], L2).\nelementalRE(negSet([range(0'A, 0'Z), range(0'a, 0'z), range(0'0, 0'9), char(0'_)]), [0'\\\\, 0'W|L2], L2).\nelementalRE(posSet([range(0'0, 0'9)]), [0'\\\\, 0'd|L2], L2).\nelementalRE(negSet([range(0'0, 0'9)]), [0'\\\\, 0'D|L2], L2).\nelementalRE(posSet([char(0x20), char(0'\\t), char(0'\\r), char(0'\\n), char(0'\\v), char(0'\\f)]), [0'\\\\, 0's|L2], L2).\nelementalRE(negSet([char(0x20), char(0'\\t), char(0'\\r), char(0'\\n), char(0'\\v), char(0'\\f)]), [0'\\\\, 0'S|L2], L2).\nelementalRE(char(C), [0'\\\\, C|L2], L2) :-\n re_metachar([C]).\nelementalRE(char(C), [C|L2], L2) :-\n \\+re_metachar([C]).\nelementalRE(negSet(X), [0'[, 0'^|L2], L4) :-\n !,\n setItems(X, L2, [0']|L4]).\nelementalRE(posSet(X), [0'[|L2], L4) :-\n setItems(X, L2, [0']|L4]).\n\nre_metachar([0'\\\\]).\nre_metachar([0'|]).\nre_metachar([0'*]).\nre_metachar([0'?]).\nre_metachar([0'+]).\nre_metachar([0'.]).\nre_metachar([0'[]).\nre_metachar([0'$]).\nre_metachar([0'(]).\nre_metachar([0')]).\n\nsetItems([Item1|MoreItems], L1, L3) :-\n setItem(Item1, L1, L2),\n setItems(MoreItems, L2, L3).\nsetItems([Item1], L1, L2) :-\n setItem(Item1, L1, L2).\n\nsetItem(posSet([range(0'A, 0'Z), range(0'a, 0'z), range(0'0, 0'9), char(0'_)]), [0'\\\\, 0'w|L2], L2).\nsetItem(negSet([range(0'A, 0'Z), range(0'a, 0'z), range(0'0, 0'9), char(0'_)]), [0'\\\\, 0'W|L2], L2).\nsetItem(posSet([range(0'0, 0'9)]), [0'\\\\, 0'd|L2], L2).\nsetItem(negSet([range(0'0, 0'9)]), [0'\\\\, 0'D|L2], L2).\nsetItem(posSet([char(0x20), char(0'\\t), char(0'\\r), char(0'\\n), char(0'\\v), char(0'\\f)]), [0'\\\\, 0's|L2], L2).\nsetItem(negSet([char(0x20), char(0'\\t), char(0'\\r), char(0'\\n), char(0'\\v), char(0'\\f)]), [0'\\\\, 0'S|L2], L2).\nsetItem(char(C), [0'\\\\, C|L2], L2) :-\n set_metachar([C]).\nsetItem(char(C), [C|L2], L2) :-\n \\+set_metachar([C]).\nsetItem(range(A, B), L1, L4) :-\n setItem(char(A), L1, [0'-|L3]),\n setItem(char(B), L3, L4).\n\nset_metachar([0'\\\\]).\nset_metachar([0']]).\nset_metachar([0'-]).\n\nregexp_wildcard([], []) :-\n !.\nregexp_wildcard([0'*|A], [0'., 0'*|B]) :-\n !,\n regexp_wildcard(A, B).\nregexp_wildcard([A|B], [A|C]) :-\n regexp_wildcard(B, C).\n\nfm(A) :-\n format(user_error, '~n*** ~q~n', [A]),\n flush_output(user_error).\n\nmf(A) :-\n forall(\n catch(A, _, fail),\n ( portray_clause(user_error, A),\n write(user_error, '\\n')\n )\n ),\n flush_output(user_error).\n";
5
5
  exports.default = eye;