# Modulo in constraints

**URL:** <https://discourse.ats-lang.org/t/modulo-in-constraints/259>\
**Category:** Google Group\
**Created:** [February 2, 2015, 11:48pm UTC](https://discourse.ats-lang.org/t/modulo-in-constraints/259 "2015-02-02T23:48:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [February 2, 2015, 11:48pm UTC](https://discourse.ats-lang.org/t/modulo-in-constraints/259/1 "2015-02-02T23:48:24Z")

</div>

Hi,

I’ve been playing around with P2 from project euler. I have a long way to  
go (for the proof; even a semi-shoddy proof at that), but think I’ve made  
significant progress. I’m now getting “ye olde constraint error”:

$ patsopt.exe -tc -d P2-bbarker.dats  
/home/brand\_000/ATS-Postiats-test/contrib/bbarker/PEULER/P2/P2-bbarker.dats:  
857(line=55, offs=28) – 857(line=55, offs=28): error(3): unsolved  
constraint: C3NSTRprop(main; S2Eapp(S2Ecst(==); S2Eapp(S2Ecst(mod);  
S2Eapp(S2Ecst(+); S2EVar(4158-\>S2Evar(ln1(7667))),  
S2EVar(4159-\>S2Evar(ln2(7666)))), S2Eintinf(2)), S2Eintinf(0)))  
typechecking has failed: there are some unsolved constraints: please  
inspect the above reported error message(s) for information.  
exit(ATS): uncaught exception:  
\_2home\_2brand\_000\_2ATS\_2dPostiats\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)

Here’s the version of code pertinent to the question:

> <https://github.com/bbarker/ATS-Postiats-test/blob/dc9fb2465d0c8a7cfdb9e693fdbfb657c5ff847a/contrib/bbarker/PEULER/P2/P2-bbarker.dats>

Of course, it is probably more likely I have a typo somewhere else … I’ve  
found many already, but am stuck now.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [February 3, 2015, 12:06am UTC](https://discourse.ats-lang.org/t/modulo-in-constraints/259/2 "2015-02-03T00:06:11Z")

</div>

nmod does not give you a type that is accurate enough for this task.  
Try to use n - 2\*half(n) (instead of nmod(n,2)) for this case.

As a rule of thumb, it is always a good idea to introduce a function of  
your own  
in this kind of situation:

fun my\_mod2 {n:nat} (int(n)): int(n%2)

Then move on. You can always come back to deal with these introduced  
functions later.

When programming, a programmer so often follows whatever the library  
provides.

IMO, a programmer should be “self-centered” 🙂

Try to introduce whatever functions you need (if you can quickly convince  
yourself  
that these functions can be readily implemented based on some kind library).On Monday, February 2, 2015 at 6:48:24 PM UTC-5, Brandon Barker wrote:

> Hi,
> 
> I’ve been playing around with P2 from project euler. I have a long way to  
> go (for the proof; even a semi-shoddy proof at that), but think I’ve made  
> significant progress. I’m now getting “ye olde constraint error”:
> 
> $ patsopt.exe -tc -d P2-bbarker.dats  
> /home/brand\_000/ATS-Postiats-test/contrib/bbarker/PEULER/P2/P2-bbarker.dats:  
> 857(line=55, offs=28) – 857(line=55, offs=28): error(3): unsolved  
> constraint: C3NSTRprop(main; S2Eapp(S2Ecst(==); S2Eapp(S2Ecst(mod);  
> S2Eapp(S2Ecst(+); S2EVar(4158-\>S2Evar(ln1(7667))),  
> S2EVar(4159-\>S2Evar(ln2(7666)))), S2Eintinf(2)), S2Eintinf(0)))  
> typechecking has failed: there are some unsolved constraints: please  
> inspect the above reported error message(s) for information.  
> exit(ATS): uncaught exception:  
> \_2home\_2brand\_000\_2ATS\_2dPostiats\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)
> 
> Here’s the version of code pertinent to the question:
> 
> [https://github.com/bbarker/ATS-Postiats-test/blob/dc9fb2465d0c8a7cfdb9e693fdbfb657c5ff847a/contrib/bbarker/PEULER/P2/P2-bbarker.dats](https://github.com/bbarker/ATS-Postiats-test/blob/dc9fb2465d0c8a7cfdb9e693fdbfb657c5ff847a/contrib/bbarker/PEULER/P2/P2-bbarker.dats)
> 
> Of course, it is probably more likely I have a typo somewhere else …  
> I’ve found many already, but am stuck now.

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [February 3, 2015, 2:44am UTC](https://discourse.ats-lang.org/t/modulo-in-constraints/259/3 "2015-02-03T02:44:40Z")

</div>

The type for my\_mod2 does not look right.On Mon, Feb 2, 2015 at 9:39 PM, Brandon Barker [brandon...@gmail.com](mailto:brandon...@gmail.com) wrote:

> Good advice, thanks! But I now seem to be getting an invalid constraint  
> popping up: ln1 + ln2 = ln1, i.e.:
> 
> /home/brand\_000/ATS-Postiats-test/contrib/bbarker/PEULER/P2/P2-bbarker.dats:  
> 1019(line=62, offs=7) – 1064(line=62, offs=52): error(3): unsolved  
> constraint: C3NSTRprop(main; S2Eeqeq(S2Eapp(S2Ecst(add\_int\_int);  
> S2Evar(ln1(7703)), S2Evar(ln2(7702))); S2Evar(ln1(7703))))  
> typechecking has failed: there are some unsolved constraints: please  
> inspect the above reported error message(s) for information.  
> exit(ATS): uncaught exception:  
> \_2home\_2brand\_000\_2ATS\_2dPostiats\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)
> 
> Of course it is clear to me that is an invalid constraint, I just don’t  
> know why I have it. It is suggestive that I have a typo somewhere that is  
> making the loop signature unhappy.
> 
> Here’s my update:  
> [fixed a constraint issue · bbarker/ATS-Postiats-test@46f94f7 · GitHub](https://github.com/bbarker/ATS-Postiats-test/commit/46f94f770641b7916004a4fc550ff4e3f07c7b8a)
> 
> On Mon, Feb 2, 2015 at 7:06 PM, gmhwxi [gmh...@gmail.com](mailto:gmh...@gmail.com) wrote:
> 
> > nmod does not give you a type that is accurate enough for this task.  
> > Try to use n - 2\*half(n) (instead of nmod(n,2)) for this case.
> > 
> > As a rule of thumb, it is always a good idea to introduce a function of  
> > your own  
> > in this kind of situation:
> > 
> > fun my\_mod2 {n:nat} (int(n)): int(n%2)
> > 
> > Then move on. You can always come back to deal with these introduced  
> > functions later.
> > 
> > When programming, a programmer so often follows whatever the library  
> > provides.
> > 
> > IMO, a programmer should be “self-centered” 🙂
> > 
> > Try to introduce whatever functions you need (if you can quickly convince  
> > yourself  
> > that these functions can be readily implemented based on some kind  
> > library).
> > 
> > On Monday, February 2, 2015 at 6:48:24 PM UTC-5, Brandon Barker wrote:
> > 
> > > Hi,
> > > 
> > > I’ve been playing around with P2 from project euler. I have a long way  
> > > to go (for the proof; even a semi-shoddy proof at that), but think I’ve  
> > > made significant progress. I’m now getting “ye olde constraint error”:
> > > 
> > > $ patsopt.exe -tc -d P2-bbarker.dats  
> > > /home/brand\_000/ATS-Postiats-test/contrib/bbarker/PEULER/P2/P2-bbarker.dats:  
> > > 857(line=55, offs=28) – 857(line=55, offs=28): error(3): unsolved  
> > > constraint: C3NSTRprop(main; S2Eapp(S2Ecst(==); S2Eapp(S2Ecst(mod);  
> > > S2Eapp(S2Ecst(+); S2EVar(4158-\>S2Evar(ln1(7667))),  
> > > S2EVar(4159-\>S2Evar(ln2(7666)))), S2Eintinf(2)), S2Eintinf(0)))  
> > > typechecking has failed: there are some unsolved constraints: please  
> > > inspect the above reported error message(s) for information.  
> > > exit(ATS): uncaught exception: _2home\_2brand\_000\_2ATS_  
> > > 2dPostiats\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)
> > > 
> > > Here’s the version of code pertinent to the question:  
> > > [https://github.com/bbarker/ATS-Postiats-test/blob/](https://github.com/bbarker/ATS-Postiats-test/blob/)  
> > > dc9fb2465d0c8a7cfdb9e693fdbfb657c5ff847a/contrib/bbarker/  
> > > PEULER/P2/P2-bbarker.dats
> > > 
> > > Of course, it is probably more likely I have a typo somewhere else …  
> > > I’ve found many already, but am stuck now.
> > 
> > –  
> > You received this message because you are subscribed to the Google Groups  
> > “ats-lang-users” group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> > To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/ats-lang-users/09491914-f512-4716-a091-e072541c1e0d%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/09491914-f512-4716-a091-e072541c1e0d%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/ats-lang-users/09491914-f512-4716-a091-e072541c1e0d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/09491914-f512-4716-a091-e072541c1e0d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> –  
> Brandon Barker  
> [brandon...@gmail.com](mailto:brandon...@gmail.com)
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/CAORbNRoEFUjMdTrpiyij0ZzOYuMi6D%3DOtojPCVKWoecBFZpQxA%40mail.gmail.com](https://groups.google.com/d/msgid/ats-lang-users/CAORbNRoEFUjMdTrpiyij0ZzOYuMi6D%3DOtojPCVKWoecBFZpQxA%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/CAORbNRoEFUjMdTrpiyij0ZzOYuMi6D%3DOtojPCVKWoecBFZpQxA%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/CAORbNRoEFUjMdTrpiyij0ZzOYuMi6D%3DOtojPCVKWoecBFZpQxA%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [February 3, 2015, 2:39am UTC](https://discourse.ats-lang.org/t/modulo-in-constraints/259/4 "2015-02-03T02:39:08Z")

</div>

Good advice, thanks! But I now seem to be getting an invalid constraint  
popping up: ln1 + ln2 = ln1, i.e.:

/home/brand\_000/ATS-Postiats-test/contrib/bbarker/PEULER/P2/P2-bbarker.dats:  
1019(line=62, offs=7) – 1064(line=62, offs=52): error(3): unsolved  
constraint: C3NSTRprop(main; S2Eeqeq(S2Eapp(S2Ecst(add\_int\_int);  
S2Evar(ln1(7703)), S2Evar(ln2(7702))); S2Evar(ln1(7703))))  
typechecking has failed: there are some unsolved constraints: please  
inspect the above reported error message(s) for information.  
exit(ATS): uncaught exception:  
\_2home\_2brand\_000\_2ATS\_2dPostiats\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)

Of course it is clear to me that is an invalid constraint, I just don’t  
know why I have it. It is suggestive that I have a typo somewhere that is  
making the loop signature unhappy.

Here’s my update:  
[https://github.com/bbarker/ATS-Postiats-test/commit/46f94f770641b7916004a4fc550ff4e3f07c7b8aOn](https://github.com/bbarker/ATS-Postiats-test/commit/46f94f770641b7916004a4fc550ff4e3f07c7b8aOn) Mon, Feb 2, 2015 at 7:06 PM, gmhwxi [gmh...@gmail.com](mailto:gmh...@gmail.com) wrote:

> nmod does not give you a type that is accurate enough for this task.  
> Try to use n - 2\*half(n) (instead of nmod(n,2)) for this case.
> 
> As a rule of thumb, it is always a good idea to introduce a function of  
> your own  
> in this kind of situation:
> 
> fun my\_mod2 {n:nat} (int(n)): int(n%2)
> 
> Then move on. You can always come back to deal with these introduced  
> functions later.
> 
> When programming, a programmer so often follows whatever the library  
> provides.
> 
> IMO, a programmer should be “self-centered” 🙂
> 
> Try to introduce whatever functions you need (if you can quickly convince  
> yourself  
> that these functions can be readily implemented based on some kind  
> library).
> 
> On Monday, February 2, 2015 at 6:48:24 PM UTC-5, Brandon Barker wrote:
> 
> > Hi,
> > 
> > I’ve been playing around with P2 from project euler. I have a long way to  
> > go (for the proof; even a semi-shoddy proof at that), but think I’ve made  
> > significant progress. I’m now getting “ye olde constraint error”:
> > 
> > $ patsopt.exe -tc -d P2-bbarker.dats  
> > /home/brand\_000/ATS-Postiats-test/contrib/bbarker/PEULER/P2/P2-bbarker.dats:  
> > 857(line=55, offs=28) – 857(line=55, offs=28): error(3): unsolved  
> > constraint: C3NSTRprop(main; S2Eapp(S2Ecst(==); S2Eapp(S2Ecst(mod);  
> > S2Eapp(S2Ecst(+); S2EVar(4158-\>S2Evar(ln1(7667))),  
> > S2EVar(4159-\>S2Evar(ln2(7666)))), S2Eintinf(2)), S2Eintinf(0)))  
> > typechecking has failed: there are some unsolved constraints: please  
> > inspect the above reported error message(s) for information.  
> > exit(ATS): uncaught exception: _2home\_2brand\_000\_2ATS_  
> > 2dPostiats\_2src\_2pats\_error\_2esats\_\_FatalErrorExn(1025)
> > 
> > Here’s the version of code pertinent to the question:  
> > [https://github.com/bbarker/ATS-Postiats-test/blob/](https://github.com/bbarker/ATS-Postiats-test/blob/)  
> > dc9fb2465d0c8a7cfdb9e693fdbfb657c5ff847a/contrib/bbarker/  
> > PEULER/P2/P2-bbarker.dats
> > 
> > Of course, it is probably more likely I have a typo somewhere else …  
> > I’ve found many already, but am stuck now.
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/09491914-f512-4716-a091-e072541c1e0d%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/09491914-f512-4716-a091-e072541c1e0d%40googlegroups.com)  
> [https://groups.google.com/d/msgid/ats-lang-users/09491914-f512-4716-a091-e072541c1e0d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/ats-lang-users/09491914-f512-4716-a091-e072541c1e0d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .

Brandon Barker  
[brandon...@gmail.com](mailto:brandon...@gmail.com)
