Commit 8c6eaae0 authored by SOLIMAN Sylvain's avatar SOLIMAN Sylvain
Browse files

trying to get any expression in FOLTL

parent edaf61b3
......@@ -4,7 +4,6 @@
% Grammar
foltl/1,
foltl_predicate/1,
foltl_expression/1,
parameter_between_interval/1,
variable_objective/1,
time_value/1,
......@@ -124,80 +123,43 @@ foltl(F) :-
foltl_predicate(E = F) :-
foltl_expression(E),
foltl_expression(F).
arithmetic_expression(E),
arithmetic_expression(F).
foltl_predicate(E <> F) :-
foltl_expression(E),
foltl_expression(F).
arithmetic_expression(E),
arithmetic_expression(F).
foltl_predicate(E << F) :-
foltl_expression(E),
foltl_expression(F).
arithmetic_expression(E),
arithmetic_expression(F).
foltl_predicate(E >> F) :-
foltl_expression(E),
foltl_expression(F).
arithmetic_expression(E),
arithmetic_expression(F).
foltl_predicate(E < F) :-
foltl_expression(E),
foltl_expression(F).
arithmetic_expression(E),
arithmetic_expression(F).
foltl_predicate(E <= F) :-
foltl_expression(E),
foltl_expression(F).
arithmetic_expression(E),
arithmetic_expression(F).
foltl_predicate(E > F) :-
foltl_expression(E),
foltl_expression(F).
arithmetic_expression(E),
arithmetic_expression(F).
foltl_predicate(E >= F) :-
foltl_expression(E),
foltl_expression(F).
:- grammar(foltl_expression).
foltl_expression(E + F) :-
foltl_expression(E),
foltl_expression(F).
foltl_expression(E - F) :-
foltl_expression(E),
foltl_expression(F).
foltl_expression(E * F) :-
foltl_expression(E),
foltl_expression(F).
foltl_expression(E ^ F) :-
foltl_expression(E),
foltl_expression(F).
foltl_expression(E / F) :-
foltl_expression(E),
foltl_expression(F).
foltl_expression(E) :-
number(E).
foltl_expression(FunctionApplication) :-
function_application(foltl_expression, FunctionApplication).
foltl_expression(E) :-
name(E).
foltl_expression([E]) :-
name(E).
arithmetic_expression(E),
arithmetic_expression(F).
:- grammar(time_value).
......@@ -544,7 +506,7 @@ expand_formula(Formula, ExpandedFormula) :-
grammar_map(
foltl,
[foltl:foltl:expand_formula,
foltl_expression:foltl:expand_expression],
arithmetic_expression:foltl:expand_expression],
Formula,
ExpandedFormula
).
......@@ -565,8 +527,8 @@ expand_expression(Expression, ExpandedExpression) :-
expand_expression(Expression, ExpandedExpression) :-
grammar_map(
foltl_expression,
[foltl_expression:foltl:expand_expression],
arithmetic_expression,
[arithmetic_expression:foltl:expand_expression],
Expression,
ExpandedExpression
).
......@@ -892,20 +854,15 @@ generate_expression(A) :-
!,
format('(*i)[~d]', [Index]).
generate_expression(A^B) :-
!,
write('pow('),
generate_expression(if C then A else B) :-
gsl:write_condition(C),
write(' ? '),
generate_expression(A),
write(', '),
generate_expression(B),
write(')').
write(' : '),
generate_expression(B).
generate_expression(Expression) :-
binary_operator(Expression, A, Op, B),
!,
generate_expression_with_parentheses(A),
write(Op),
generate_expression_with_parentheses(B).
gsl:write_arithmetic_expression(Expression).
binary_predicate(A = B, A, '==', B).
......@@ -938,11 +895,19 @@ binary_operator(A / B, A, '/', B).
check_linearity(Formula) :-
grammar_iter(
foltl,
[foltl_expression: foltl:check_linearity_expression],
[arithmetic_expression: foltl:check_linearity_expression],
Formula
).
check_linearity_expression(+Expression) :-
!,
check_linearity_expression(Expression).
check_linearity_expression(-Expression) :-
!,
check_linearity_expression(Expression).
check_linearity_expression(Expression) :-
(
Expression = A + B
......@@ -992,6 +957,22 @@ check_linearity_expression(Expression) :-
),
check_linearity_expression(A).
check_linearity_expression(if _Condition then A else B) :-
!,
check_linearity_expression(A),
check_linearity_expression(B).
check_linearity_expression(Expression) :-
compound(Expression),
!,
(
has_variable(Expression)
->
throw(error(not_linear(Expression)))
;
true
).
check_linearity_expression(_).
......@@ -1006,13 +987,11 @@ generate_expression_with_parentheses(A) :-
has_variable(A) :-
binary_operator(A, Left, _Op, Right),
compound(A),
!,
(
has_variable(Left)
;
has_variable(Right)
).
A =.. [_ | Args],
member(Arg, Args),
has_variable(Arg).
has_variable(A) :-
is_free_variable(A).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment