Fibonacci Series in Turbo Prolog - turbo-prolog

Trying to do this turbo prolog code but is giving error.
predicates
fibo(integer,integer)
clauses
fibo(0,0).
fibo(1,1).
fibo(X,N):-
N>1,
N1=N-1,
N2=N-2,
fibo(F1,N1),
fibo(F2,N2),
F=F1+F2,
write(F),write(",").

Related

Highway intersecting Waterbodies in OSM (Overpass query)

I am trying to run an Overpass Query for extracting all the highway features (highway=*) that might overlap the water features (natural=water). The highway features might be a dead end in the water feature or invalid overlap on water feature. I am a newbie so still trying to figure out the correct query. This is the query I have used so far:
[out:json][timeout:2500];
(
way["highway"]->.h;
way["natural"="water"]->.w1;
node.(w.h).(w.w1)({{bbox}});
);
out meta;
out skel qt;
However it shows the error:
"
An error occurred during the execution of the overpass query! This is what overpass API returned:
Error: line 10: parse error: ';' expected - 'w' found.
"

R Markdown: Ready to publish regression table in WORD using miceadds::glm.cluster

I am trying to do a logistic regression with robust clustered error using miceadds::glm.cluster:
model1 <- miceadds::glm.cluster(data=df_clean3, formula=recall ~ log(Population)+NoComplaintsReported+NoCrashesFiresReported+NoInjuriesReported+NoFatalityIncidentsReported+NoOtherFailuresReported+YearOpen+label, cluster="label", family="binomial")
I want to report a ready-to-publish regression table in Microsoft Word. I have tried the below methods, but each are not the "professionally prepared" version that I am looking for.
Can someone help me with this?
1-tab_df (from the sjPlot library): It stops with the error message that:
Error in UseMethod("family") :
no applicable method for 'family' applied to an object of class "NULL"
2- Stargazer: the output table does not look neat.
3- summ (from jtools library): the output table does not look neat.
4- apa.reg.table (from apaTables library): it stops with this error message:
Error in 2:last_model_number_predictors : argument of length 0

I am getting an error in prolog in vs code please check

This is the code:
dog(rottweiler).
cat(sphynx). dog(poodle).
dog(bulldog). cat(bengal).
dog(dobermann).
cat(himalayan). cat(singapura).
ND THE ERROR IS:-
Warning: Clauses of dog/1 are not together in the source-file
Warning: Earlier definition at c:/users/dell/desktop/prolog/dog:1
Warning: Current predicate: cat/1
Warning: Use :- discontiguous dog/1. to suppress this message
Warning: c:/users/dell/desktop/prolog/dog:4:
Warning: Clauses of cat/1 are not together in the source-file
Warning: Earlier definition at c:/users/dell/desktop/prolog/dog:2
Warning: Current predicate: dog/1
Warning: Use :- discontiguous cat/1. to suppress this message.
TRUE
In Prolog, an n-ary predicate p, for n≥0, is defined by a procedure, which consists of one or more clauses whose conclusions are terms of the form p(a1, ..., an), where each a_i is an argument. Clauses belonging to the same procedure are expected to be declared in sequence, contiguously.
When the clauses of two or more distinct procedures appear interleaved in the source code, the compiler produces the warning messages you get. To suppress such messages, you can use a directive of the form :- discontiguous predicate/arity.
For example:
:- discontiguous dog/1.
:- discontiguous cat/1.
dog(rottweiler).
cat(sphynx).
dog(poodle).
dog(bulldog).
cat(bengal).
dog(dobermann).
cat(himalayan).
cat(singapura).
Note, however, that the best option is to follow the Prolog convention and modify your code as follows:
% clauses of the first procedure
dog(rottweiler).
dog(poodle).
dog(bulldog).
dog(dobermann).
% clauses of the second procedure
cat(sphynx).
cat(bengal).
cat(himalayan).
cat(singapura).

How to encode normalized(A,B) properly?

I am using clingo to solve a homework problem and stumbled upon something I can't explain:
normalized(0,0).
normalized(A,1) :-
A != 0.
normalized(10).
In my opinion, normalized should be 0 when the first parameter is 0 or 1 in every other case.
Running clingo on that, however, produces the following:
test.pl:2:1-3:12: error: unsafe variables in:
normalized(A,1):-[#inc_base];A!=0.
test.pl:2:12-13: note: 'A' is unsafe
Why is A unsafe here?
According to Programming with CLINGO
Some error messages say that the program
has “unsafe variables.” Such a message usually indicates that the head of one of
the rules includes a variable that does not occur in its body; stable models of such
programs may be infinite.
But in this example A is present in the body.
Will clingo produce an infinite set consisting of answers for all numbers here?
I tried adding number(_) around the first parameter and pattern matching on it to avoid this situation but with the same result:
normalized(number(0),0).
normalized(A,1) :-
A=number(B),
B != 0.
normalized(number(10)).
How would I write normalized properly?
With "variables occuring in the body" actually means in a positive literal in the body. I can recommend the official guide: https://github.com/potassco/guide/releases/
The second thing, ASP is not prolog. Your rules get grounded, i.e. each first order variable is replaced with its domain. In your case A has no domain.
What would be the expected outcome of your program ?
normalized(12351,1).
normalized(my_mom,1).
would all be valid replacements for A so you create an infinite program. This is why 'A' has to be bounded by a domain. For example:
dom(a). dom(b). dom(c). dom(100).
normalized(0,0).
normalized(A,1) :- dom(A).
would produce
normalize(0,0).
normalize(a,1).
normalize(b,1).
normalize(c,1).
normalize(100,1).
Also note that there is no such thing as number/1. ASP is a typefree language.
Also,
normalized(10).
is a different predicate with only one parameter, I do not know how this will fit in your program.
Maybe your are looking for something like this:
dom(1..100).
normalize(0,0).
normalize(X,1) :- dom(X).
foo(43).
bar(Y) :- normalize(X,Y), foo(X).

CP-SAT is slow when it creates the goal function

Could you explain to me what CP-SAT does when it created the goal function? With big models this action is very slow.
the function is the following:
sum(sum(self.suggested_decisions[r][d]*(
((int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_1'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CA_S1'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FA']*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_1'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_1'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CB_S1'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FB']*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_1'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_1'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CC_S1'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FC']*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_1'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_1'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CD_S1'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FD']*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_1'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_1'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CE_S1'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FE']*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_1'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_2'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CA_S2'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FA']*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_2'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_2'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CB_S2'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FB']*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_2'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_2'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CC_S2'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FC']*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_2'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_2'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CD_S2'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FD']*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_2'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_2'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CE_S2'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FE']*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_2'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_3'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CA_S3'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FA']*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_3'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_3'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CB_S3'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FB']*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_3'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_3'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CC_S3'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FC']*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_3'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_3'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CD_S3'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FD']*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_3'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_3'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CE_S3'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FE']*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_3'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_4'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CA_S4'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FA']*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_4'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_4'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CB_S4'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FB']*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_4'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_4'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CC_S4'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FC']*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_4'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_4'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CD_S4'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FD']*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_4'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_4'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CE_S4'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FE']*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_4'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_5'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CA_S5'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FA']*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_5'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_5'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CB_S5'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FB']*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_5'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_5'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CC_S5'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FC']*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_5'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_5'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CD_S5'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FD']*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_5'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_5'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CE_S5'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FE']*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_5'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_6'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CA_S6'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FA']*self.scenario.dataset['BandA'][r]*self.scenario.dataset['SCORE_CLASS_6'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_6'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CB_S6'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FB']*self.scenario.dataset['BandB'][r]*self.scenario.dataset['SCORE_CLASS_6'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_6'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CC_S6'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FC']*self.scenario.dataset['BandC'][r]*self.scenario.dataset['SCORE_CLASS_6'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_6'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CD_S6'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FD']*self.scenario.dataset['BandD'][r]*self.scenario.dataset['SCORE_CLASS_6'][r]))+
(int(self.scenario.dataset['CAPITAL'][r])*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_6'][r]*int(self.scenario.constants['scaling_factor']*self.scenario.constants['recovery_rate_CE_S6'])*self.scenario.decisions[d].attributes['max_capital_recoverable']-int(self.scenario.constants['scaling_factor']*self.scenario.decisions[d].attributes['FE']*self.scenario.dataset['BandE'][r]*self.scenario.dataset['SCORE_CLASS_6'][r])))
*(1*self.scenario.constants['scaling_factor']-int(self.scenario.constants['scaling_factor']*self.scenario.dataset['SCORE'][r]))
)for r in self.all_records) for d in self.all_decisions)
Where all self.all_records=60.000 and self.all_decisions=7
The language is python.
the sum() API creates an unbalanced syntax tree that is very expensive to parse for large objectives.
I suggest using cp_model.LinearExpr.ScalProd(variable_list, coefficient_list) (see doc entry)