start_synthesis_from_ui_aux(Operation, action, (PosInput,PosOutput), (NegInput,NegOutput), (DistStateCache,FinalAction)) :-
% synthesizing the action already succeeded but synthesizing an appropriate guard afterwards has been suspended by
% finding a distingushing state, the synthesized action is asserted and we just synthesize the guard here
catch(synthesis_context(_, DistStateCache, _, PreCondVars, _, guard, OldPosInput, OldNegInput, Action),
error(existence_error(_,_),_), fail),
\+ catch(synthesis_context(_, _, _, _, _, action, _, _, _),
error(existence_error(_,_),_), fail),
Action \== temp(_),
!,
( add_operation_parameter_values_to_examples(PosInput, PosOutput, NegInput, NegOutput, [Action], ExtendedPosInput, ExtendedNegInput)
; PosInput = ExtendedPosInput,
NegInput = ExtendedNegInput
),
keep_asserted_initial_examples(ExtendedPosInput, ExtendedNegInput, OldPosInput, OldNegInput, NewPosInput, NewNegInput),
post_synthesize_action(Operation, PreCondVars, NewPosInput, PosOutput, NewNegInput, NegOutput, [], Action, FinalAction).
start_synthesis_from_ui_aux(Operation, action, (PosInput,PosOutput), (NegInput,NegOutput), (NewDistStateCache,FinalAction)) :-
% synthesis type is action but the simultaneous generation of a guard has been suspended by finding a distinguishing state,
% synthesizing the action has not succeeded yet
catch(synthesis_context(_, PreDistStateCache, _, PreCondVars, ValidInvariantsOrGuards, guard, OldPosInput, OldNegInput, temp(Actions)),
error(existence_error(_,_),_), fail),
retractall(synthesis_context(_, _, _, _, ValidGuards, guard, _, _, _)),
( add_operation_parameter_values_to_examples(PosInput, PosOutput, NegInput, NegOutput, Actions, ExtendedPosInput, ExtendedNegInput)
; PosInput = ExtendedPosInput,
NegInput = ExtendedNegInput
),
keep_asserted_initial_examples(ExtendedPosInput, ExtendedNegInput, OldPosInput, OldNegInput, NewPosInput, NewNegInput),
maplist(get_varname_from_id_node, PreCondVars, PreVarNames),
% therefore we start/restart synthesis of a guard
synthesized_operation_uses_parameters(Actions, OperationUsesParameters),
prepare_synthesis_of_guard_by_examples(OperationUsesParameters, PreVarNames, (ValidGuards,Operation), NewPosInput, NewNegInput, PrePositive, PreNegative, PreLibrary,
PreParameterAmount, PreM1, PreCurrentVars, PreBehavioralConstraint, PreLocationVars, PreSolution),
synthesis_from_examples(Operation, b(truth,pred,[]), PreDistStateCache, PreLibrary, 1, PreCurrentVars, PreCurrentVars, ValidInvariantsOrGuards, guard, PrePositive, PreNegative,
PreBehavioralConstraint, PreLocationVars, PreM1, PreParameterAmount, PreSolution, PreCondition, NewDistStateCache),
distinguishing_state_or_synthesize_action(Operation, PreCondition, NewDistStateCache, (PosInput,PosOutput), (NegInput,NegOutput), FinalAction).
start_synthesis_from_ui_aux(Operation, action, (PosInput,PosOutput), (NegInput,NegOutput), (NewDistStateCache,FinalAction)) :-
% synthesizing an action has been suspended by a distinguishing transition, but the user validated the distinguishing example to be negative
\+ catch(synthesis_context(_, _, _, _, _, guard, _, _, _),
error(existence_error(_,_),_), fail),
catch(synthesis_context(_, DistStateCache, _, _, ValidInvariantsOrGuards, action, OldPosInput, OldNegInput, temp(Action)),
error(existence_error(_,_),_), fail),
length(OldPosInput, PLen),
length(PosInput, PLen),
length(OldNegInput, NLen),
length(NegInput, NLen),
NegInput \= [],
!,
( add_operation_parameter_values_to_examples(PosInput, PosOutput, NegInput, NegOutput, [Action], ExtendedPosInput, ExtendedNegInput)
; PosInput = ExtendedPosInput,
NegInput = ExtendedNegInput
),
keep_asserted_initial_examples(ExtendedPosInput, ExtendedNegInput, OldPosInput, OldNegInput, NewPosInput, NewNegInput),
ExtendedPosInput = [Example|_],
maplist(get_varname_from_node_info, Example, PreVarNames),
% therefore we start/restart synthesis of a guard
synthesized_operation_uses_parameters([Action], OperationUsesParameters),
prepare_synthesis_of_guard_by_examples(OperationUsesParameters, PreVarNames, (ValidInvariantsOrGuards,Operation), NewPosInput, NewNegInput, PrePositive, PreNegative, PreLibrary,
PreParameterAmount, PreM1, PreCurrentVars, PreBehavioralConstraint, PreLocationVars, PreSolution),
synthesis_from_examples(Operation, b(truth,pred,[]), DistStateCache, PreLibrary, 1, PreCurrentVars, PreCurrentVars, ValidInvariantsOrGuards, guard, PrePositive, PreNegative,
PreBehavioralConstraint, PreLocationVars, PreM1, PreParameterAmount, PreSolution, PreCondition, NewDistStateCache),
distinguishing_state_or_synthesize_action(Operation, PreCondition, NewDistStateCache, (PosInput,PosOutput), (NegInput,NegOutput), FinalAction).
start_synthesis_from_ui_aux(Operation, action, (PosInput,PosOutput), (NegInput,NegOutput), ((PosDistInput,NegDistInput),FinalAction)) :-
% synthesizing an action has been suspended by a distinguishing transition, no guard
\+ catch(synthesis_context(_, _, _, _, _, guard, _, _, _),
error(existence_error(_,_),_), fail),
catch(synthesis_context(DistTransitionCache, DistStateCache, _, PreCondVars, ValidGuards, action, OldPosInput, OldPosOutput, _),
error(existence_error(_,_),_), fail),
retractall(synthesis_context(_, _, _, _, _, action, _, _, _)),
keep_asserted_initial_examples(PosInput, PosOutput, OldPosInput, OldPosOutput, NewPosInput, NewPosOutput),
prepare_synthesis_of_action_by_examples(Operation, NewPosInput, NewPosOutput, Library, ParameterAmount, M1, CurrentVars, BehavioralConstraint, LocationVars, Solution),
DistStateCache = (PosDist,NegDist),
append(NegInput, NegDist, NewNegDist),
synthesis_from_examples(Operation, DistTransitionCache, (PosDist,NewNegDist), Library, 1, CurrentVars, PreCondVars, ValidGuards, action,
NewPosInput, NewPosOutput, BehavioralConstraint, LocationVars, M1, ParameterAmount, Solution, Synthesized, (PosDistInput,NegDistInput)),
!,
Synthesized \= none,
post_synthesize_action(Operation, CurrentVars, NewPosInput, NewPosOutput, NegInput, NegOutput, NegDistInput, Synthesized, FinalAction).
start_synthesis_from_ui_aux(Operation, action, (PosInput,PosOutput), (NegInput,NegOutput), (DistStateCache,Synthesized)) :-
% no context asserted, start new synthesis instance for type action,
% check if the machine already satisfies the behavior and relax a guard or synthesize a new operation
!,
behavior_satisfied_or_extend_machine(Operation, PosInput, NegInput, PosOutput, NegOutput, Synthesized),
( catch(synthesis_context(_, DistStateCache, _, _, _, _, _, _, _), error(existence_error(_,_),_), fail)
->
true
; DistStateCache = ([],[])
).
start_synthesis_from_ui_aux(Operation, SynthesisType, (PosInput,_), (NegInput,_), (DistStateCache,Synthesized)) :-
SynthesisType \= action,
% go on synthesizing the guard/invariant using the validated distinguishing state
catch(synthesis_context(_, PreDistStateCache, _, PreCondVars, ValidInvariantsOrGuards, SynthesisType, OldPosInput, OldNegInput, _),
error(existence_error(_,_),_), fail),
retractall(synthesis_context(_, _, _, _, _, SynthesisType, _, _, _)),
keep_asserted_initial_examples(PosInput, NegInput, OldPosInput, OldNegInput, NewPosInput, NewNegInput),
maplist(get_varname_from_id_node, PreCondVars, PreVarNames),
machine_operation_uses_parameters(Operation, OperationUsesParameters),
prepare_synthesis_of_guard_by_examples(OperationUsesParameters, PreVarNames, (ValidInvariantsOrGuards,Operation), NewPosInput, NewNegInput, PrePositive, PreNegative, PreLibrary, PreParameterAmount, PreM1, PreCurrentVars,
PreBehavioralConstraint, PreLocationVars, PreSolution),
synthesis_from_examples(Operation, b(truth,pred,[]), PreDistStateCache, PreLibrary, 1, PreCurrentVars, PreCurrentVars, ValidInvariantsOrGuards, SynthesisType, PrePositive,
PreNegative, PreBehavioralConstraint, PreLocationVars, PreM1, PreParameterAmount, PreSolution, TSynthesized, DistStateCache),
TSynthesized \= none,
post_synthesize_predicate(SynthesisType, TSynthesized, Synthesized).
start_synthesis_from_ui_aux(Operation, SynthesisType, (PosInput,PosOutput), (NegInput,NegOutput), (DistStateCache,Synthesized)) :-
% no context asserted, we start a new synthesis instance
\+ catch(synthesis_context(_, _, _, _, _, _, _, _, _),
error(existence_error(_,_),_), fail),
start_specific_synthesis(Operation, SynthesisType, PosInput, NegInput, PosOutput, NegOutput, TSynthesized),
!,
( catch(synthesis_context(_, DistStateCache, _, _, _, _, _, _, _), error(existence_error(_,_),_), fail)
->
true
; DistStateCache = ([],[])
),
TSynthesized \= none,
post_synthesize_predicate(SynthesisType, TSynthesized, Synthesized).