Skip to content

Conversation

@jodavies
Copy link
Collaborator

This PR fixes #554 and #599 .

The behaviour that I noted at the end of #554 (comment) is intended. When creating the {} sets, it finds that they exist already and doesn't create a copy:
https://github.com/vermaseren/form/blob/8abec49f876deae1d13ad159519b301f0b140dc5/sources/names.c#L2471-L2474

Thus the following defines only xs and xs2:

#-
off stats;
On names;
CF f;
S x,y;
set xs: ;
set xs2: 1,2;
L F = f(1)+f(2)+f(3);
id f(x?{}) = x;
id f(y?{1,2}) = x^y;
print;
.end

There is one point for discussion: the second commit implies that id f(x?!{}) = x; also does not match. In principle one could claim that x is indeed not a member of the empty set, so that this should match, but to my knowledge there will never be a case where x? does match an empty set (x? can not be "nothing" in FORM currently) so it feels a bit odd to match in this case to me.

One could even claim that x?{} could be a syntax error and terminate. In that case the x?!{} question is irrelevant.

Any thoughts?

@coveralls
Copy link

coveralls commented Dec 13, 2024

Coverage Status

coverage: 50.819% (+0.08%) from 50.74%
when pulling 160f9d4 on jodavies:fix-sets
into 1d5e40b on vermaseren:master.

@tueda
Copy link
Collaborator

tueda commented Dec 17, 2024

In principle, the set for the pattern matching can be changed at compile-time, for example,

CF f,g;
S x;

#$x = f(1,3,5);

#inside $x
  if (match(f(?a$a)));
  endif;
#endinside

L F = f(1,2,3,4,5,6);
L G = g(1,2,3,4,5,6);

repeat id f(?a,x? {`$a',},?b) = x * f(?a,?b);
repeat id g(?a,x?!{`$a',},?b) = x * g(?a,?b);

P;
.end

I think it should work even if $x = f() such that {`$a',} is expanded as an empty set.

@jodavies
Copy link
Collaborator Author

Do you mean that you would like all of the args of g to match !{} for $x=f()?

Otherwise, this example currently "works as intended" for $x = f();.

@tueda
Copy link
Collaborator

tueda commented Dec 17, 2024

Do you mean that you would like all of the args of g to match !{} for $x=f()?

Yes, I think this is the natural interpretation of this pattern, x?!{} (x_?(Not[MemberQ[{}, #]]&) in the Wolfram language).

@jodavies
Copy link
Collaborator Author

OK. It is not quite as simple as I thought (just goto NoMnot;) because the code at the NoM label wants to set AN.oldvalue = w[3]; and here w=0. Probably one needs AN.oldtype = old2; AN.oldvalue = oldval; goto NoMatch; as happens also further down in the set restrictions code. It looks like oldval = w[3]; is set at TestSet: for this purpose.

Generally it is not clear in what circumstances various "old" values need to be put back or not.

The set elements may come with an arbitrary number of + or - signs,
set the sign flag properly (rather, do not set the sign flag) in
the case of + signs.

Closes form-dev#599
@jodavies
Copy link
Collaborator Author

Rebased, and implements the match for !{} with oldtype etc put back as I understand it.

Copy link
Collaborator

@tueda tueda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine.

@tueda tueda linked an issue Jan 29, 2025 that may be closed by this pull request
@jodavies jodavies added this to the v4.3.2 milestone Feb 25, 2025
@jodavies jodavies merged commit 9bb422b into form-dev:master Feb 25, 2025
70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

implicitly declared sets Segfault by empty implicitly-declared set

3 participants