correct answer substitution order, equating variables to themselves (#326)

This commit is contained in:
Mark Thom
2020-04-29 01:45:42 -06:00
parent 0e1226573a
commit 7e765fe726
4 changed files with 360 additions and 458 deletions

775
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,7 @@
:- use_module(library(iso_ext)). :- use_module(library(iso_ext)).
:- use_module(library(error)). :- use_module(library(error)).
:- use_module(library(lists), [append/3]).
fabricate_var_name(VarType, VarName, N) :- fabricate_var_name(VarType, VarName, N) :-
char_code('A', AC), char_code('A', AC),
@@ -45,9 +46,10 @@ make_new_var_name(VarType, V, VarName, N, N1, VarList) :-
extend_var_list(Value, VarList, NewVarList, VarType) :- extend_var_list(Value, VarList, NewVarList, VarType) :-
term_variables(Value, Vars), term_variables(Value, Vars),
extend_var_list_(Vars, 0, VarList, NewVarList, VarType). extend_var_list_(Vars, 0, VarList, NewVarList0, VarType),
append(VarList, NewVarList0, NewVarList).
extend_var_list_([], _, VarList, VarList, _). extend_var_list_([], _, VarList, [], _).
extend_var_list_([V|Vs], N, VarList, NewVarList, VarType) :- extend_var_list_([V|Vs], N, VarList, NewVarList, VarType) :-
( var_list_contains_variable(VarList, V) -> ( var_list_contains_variable(VarList, V) ->
extend_var_list_(Vs, N, VarList, NewVarList, VarType) extend_var_list_(Vs, N, VarList, NewVarList, VarType)

View File

@@ -631,7 +631,7 @@ impl MachineState {
let mut list_of_var_eqs = vec![]; let mut list_of_var_eqs = vec![];
for (var, binding) in term_write_result.var_dict.into_iter().rev() { for (var, binding) in term_write_result.var_dict.into_iter() {
let var_atom = clause_name!(var.to_string(), indices.atom_tbl); let var_atom = clause_name!(var.to_string(), indices.atom_tbl);
let h = self.heap.h(); let h = self.heap.h();

View File

@@ -78,7 +78,7 @@ needs_bracketing(Value, Op) :-
memberchk(EqSpec, [fx,xfx,yfx]) memberchk(EqSpec, [fx,xfx,yfx])
). ).
write_goal(G, VarList, MaxDepth) :- write_goal(G, VarList, MasterVarList, MaxDepth) :-
( G = (Var = Value) -> ( G = (Var = Value) ->
write(Var), write(Var),
write(' = '), write(' = '),
@@ -90,10 +90,10 @@ write_goal(G, VarList, MaxDepth) :-
) )
; G == [] -> ; G == [] ->
write('true') write('true')
; write_term(G, [quoted(true), variable_names(VarList), max_depth(MaxDepth)]) ; write_term(G, [quoted(true), variable_names(MasterVarList), max_depth(MaxDepth)])
). ).
write_last_goal(G, VarList, MaxDepth) :- write_last_goal(G, VarList, MasterVarList, MaxDepth) :-
( G = (Var = Value) -> ( G = (Var = Value) ->
write(Var), write(Var),
write(' = '), write(' = '),
@@ -109,16 +109,16 @@ write_last_goal(G, VarList, MaxDepth) :-
) )
; G == [] -> ; G == [] ->
write('true') write('true')
; write_term(G, [quoted(true), variable_names(VarList), max_depth(MaxDepth)]) ; write_term(G, [quoted(true), variable_names(MasterVarList), max_depth(MaxDepth)])
). ).
write_eq((G1, G2), VarList, MaxDepth) :- write_eq((G1, G2), [_|VarList], MasterVarList, MaxDepth) :-
!, !,
write_goal(G1, VarList, MaxDepth), write_goal(G1, VarList, MasterVarList, MaxDepth),
write(', '), write(', '),
write_eq(G2, VarList, MaxDepth). write_eq(G2, VarList, MasterVarList, MaxDepth).
write_eq(G, VarList, MaxDepth) :- write_eq(G, VarList, MasterVarList, MaxDepth) :-
write_last_goal(G, VarList, MaxDepth). write_last_goal(G, VarList, MasterVarList, MaxDepth).
graphic_token_char(C) :- graphic_token_char(C) :-
memberchk(C, ['#', '$', '&', '*', '+', '-', '.', ('/'), ':', memberchk(C, ['#', '$', '&', '*', '+', '-', '.', ('/'), ':',
@@ -137,9 +137,8 @@ trailing_period_is_ambiguous(Value) :-
write_eqs_and_read_input(B, VarList) :- write_eqs_and_read_input(B, VarList) :-
charsio:extend_var_list(VarList, VarList, NewVarList, fabricated), charsio:extend_var_list(VarList, VarList, NewVarList, fabricated),
sort(NewVarList, SortedVarList),
'$get_b_value'(B0), '$get_b_value'(B0),
gather_goals(SortedVarList, SortedVarList, Goals), gather_goals(NewVarList, NewVarList, Goals),
( bb_get('$first_answer', true) -> ( bb_get('$first_answer', true) ->
write(' '), write(' '),
bb_put('$first_answer', false) bb_put('$first_answer', false)
@@ -147,14 +146,14 @@ write_eqs_and_read_input(B, VarList) :-
), ),
( B0 == B -> ( B0 == B ->
( Goals == [] -> ( Goals == [] ->
write('true.'), nl write('true.'), nl
; thread_goals(Goals, ThreadedGoals, (',')), ; thread_goals(Goals, ThreadedGoals, (',')),
write_eq(ThreadedGoals, NewVarList, 20), write_eq(ThreadedGoals, NewVarList, NewVarList, 20),
write('.'), write('.'),
nl nl
) )
; thread_goals(Goals, ThreadedGoals, (',')), ; thread_goals(Goals, ThreadedGoals, (',')),
write_eq(ThreadedGoals, NewVarList, 20), write_eq(ThreadedGoals, NewVarList, NewVarList, 20),
read_input(ThreadedGoals, NewVarList) read_input(ThreadedGoals, NewVarList)
). ).
@@ -163,12 +162,12 @@ read_input(ThreadedGoals, NewVarList) :-
( C = w -> ( C = w ->
nl, nl,
write(' '), write(' '),
write_eq(ThreadedGoals, NewVarList, 0), write_eq(ThreadedGoals, NewVarList, NewVarList, 0),
read_input(ThreadedGoals, NewVarList) read_input(ThreadedGoals, NewVarList)
; C = p -> ; C = p ->
nl, nl,
write(' '), write(' '),
write_eq(ThreadedGoals, NewVarList, 20), write_eq(ThreadedGoals, NewVarList, NewVarList, 20),
read_input(ThreadedGoals, NewVarList) read_input(ThreadedGoals, NewVarList)
; member(C, [';', ' ', n]) -> ; member(C, [';', ' ', n]) ->
nl, write('; '), false nl, write('; '), false