Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
GameCube
Nov 21, 2006

jony neuemonic posted:

ljw1004 is a Good Dude, read the post imo.

it was a very good post, i am just a nervous baby c#er who does not deserve the attention of a fuckin language designer

Adbot
ADBOT LOVES YOU

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Bloody posted:

i have a discrete math problem! i have the following system:

(Ax * Ay) + (Bx * By) = Cx * Cy
Ay + By = Cy * K

Ax, Bx, Cx in (1:1024)
Ay, By, Cy in (1:0.5:100)
K in 1:0.5:5

given Cx, Cy, and K, i want to solve for Ax, Ay, Bx, and By, under the constraints that:
Ideally, Bx * By = 0
if thats impossible, min(Ax - Bx)
(not all valid inputs have valid outputs and thats OK)

how do i solve this short of brute force
is there a way to solve this short of brute force

how can Bx * By = 0 given those ranges?

ignoring the ranges i first note that you've got 3 equations for 4 unknowns, which means one parameter is free. i would set Bx to be anything, then By = 0, Ay = Cy * K, and then Ax = Cx * Cy / (Cy * K) = Cx / K

HappyHippo fucked around with this message at 19:00 on Jul 22, 2016

Bloody
Mar 3, 2013

Oh right those ranges should start at 0

hobbesmaster
Jan 28, 2008

Bloody posted:

i have a discrete math problem! i have the following system:

(Ax * Ay) + (Bx * By) = Cx * Cy
Ay + By = Cy * K

Ax, Bx, Cx in (1:1024)
Ay, By, Cy in (1:0.5:100)
K in 1:0.5:5

given Cx, Cy, and K, i want to solve for Ax, Ay, Bx, and By, under the constraints that:
Ideally, Bx * By = 0
if thats impossible, min(Ax - Bx)
(not all valid inputs have valid outputs and thats OK)

how do i solve this short of brute force
is there a way to solve this short of brute force

Bx*By cannot be 0? :confused:

hobbesmaster
Jan 28, 2008

and define "brute force"

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Bloody posted:

Oh right those ranges should start at 0

see my edit then

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

Bloody posted:

i have a discrete math problem! i have the following system:

(Ax * Ay) + (Bx * By) = Cx * Cy
Ay + By = Cy * K

Ax, Bx, Cx in (1:1024)
Ay, By, Cy in (1:0.5:100)
K in 1:0.5:5

given Cx, Cy, and K, i want to solve for Ax, Ay, Bx, and By, under the constraints that:
Ideally, Bx * By = 0
if thats impossible, min(Ax - Bx)
(not all valid inputs have valid outputs and thats OK)

how do i solve this short of brute force
is there a way to solve this short of brute force

i started typing a bunch of stuff and thought i'd reduced this to something easier, but turns out i was probably wrong since the range constraints probably weren't being propagated properly. it's been a while since i've done this sort of stuff

the Bx*By = 0 case is impossible with the given ranges, so that doesn't do anything. beyond that, if it's not possible to reduce this to a simple 2 or 3 variables with modified constraints, it might be possible to get an approximate answer that has a bounded error from the true result by reducing the discrete case as much as possible, solving for the continuous case, and then taking the closest discrete result or something

honestly the first thing that comes to mind looking at this is "linear programming" but that's not quite it. unfortunately for you though, linear programming with discrete variable is NP if i recall properly

i might be completely wrong about all this though, so treat this as some Terrible Programmer Opinion

Bloody
Mar 3, 2013

yeah to come at it from another way, the ideal solution is something like:

Ay = Cy * K
Ax = Cx / K

but that runs into discretization problems: if Cx is, like, 9, then Ax needs to be 2.25, but it can't. we can work around it though by approximating it with Ax = 3 and Bx = 2 then weighting Ay and By such that the weighted average of Ax and Bx comes out to 2.25

does that make sense at all?

HoboMan
Nov 4, 2010

what is your input and what are you outputting exactly?
you want every solution, any solution, the "closest" solution given some values?

need some more constraints on this system or something since otherwise
Let K=1,Bx=By=0
=> Ax = Cx, Ay = Cy

and you're done

HoboMan fucked around with this message at 19:27 on Jul 22, 2016

Bloody
Mar 3, 2013

K, Cx, and Cy are inputs
A/B are outputs

basically there's an event that lasts for some duration at some magnitude, and an offsetting event has to happen whose integral is as close to the same (opposite sign) as the first event. in trivial cases, they're equal in duration and opposite in magnitude, but some people want the duration of the offsetting event to be asymmetric

HoboMan
Nov 4, 2010

i know this ruins the fun but your input space is only 2 mil, you could brute that puppy in a few min on a lovely laptop

HoboMan fucked around with this message at 19:40 on Jul 22, 2016

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
god i really want to go back to school for math

i was a math major before i dropped out but I'm insanely disorganized and can't really hack written tests when it comes to integrating tons of things somewhat complex things. like I understand what I'm supposed to do and understand the concepts but I end up forgetting steps and stuff.

i had a teacher who was amazing as a professor but gave really difficult tests and I refused to take calc from anyone else so I ended up stuck in calc 3 until I dropped out of school.

i'm pretty sure I'd succeed in math if I ever made it to analysis or made it into grad school or something but getting there seems to be really difficult for me.

hobbesmaster
Jan 28, 2008

HoboMan posted:

i know this ruins the fun but your input space is only 2 mil, you could brute that puppy in a few min

sounds like he needs a solution relatively quickly to fire off another event

this also probably means that a "good enough" answer is ok even if its not optimal

Share Bear
Apr 27, 2004

i been doing that stroud's engineering math book in my freetime, on the advice of this or the other programming thread, just to be able to read papers and other work in this field

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Bloody posted:

K, Cx, and Cy are inputs
A/B are outputs

basically there's an event that lasts for some duration at some magnitude, and an offsetting event has to happen whose integral is as close to the same (opposite sign) as the first event. in trivial cases, they're equal in duration and opposite in magnitude, but some people want the duration of the offsetting event to be asymmetric

so i guess Cx and Cy are in duration and magnitude of the event, and that Ax and Ay are the same of the output? then what is Bx and By?

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Share Bear posted:

i been doing that stroud's engineering math book in my freetime, on the advice of this or the other programming thread, just to be able to read papers and other work in this field

yeah i bought that, i need to figure out how to budget stuff like that into my normal work schedule

HoboMan
Nov 4, 2010

hobbesmaster posted:

sounds like he needs a solution relatively quickly to fire off another event

this also probably means that a "good enough" answer is ok even if its not optimal

yes, but how much memory you got to work with?
if you can spare it, it'd be like a 5mb table

HoboMan
Nov 4, 2010

HappyHippo posted:

so i guess Cx and Cy are in duration and magnitude of the event, and that Ax and Ay are the same of the output? then what is Bx and By?

yeah, unless there are further constraints, it seems like you always want By = 0 and Bx = Ax

JewKiller 3000
Nov 28, 2006

by Lowtax

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

HoboMan posted:

yeah, unless there are further constraints, it seems like you always want By = 0 and Bx = Ax

that seems like it would work, since the problem is a lot simpler with 0 as being part of the valid range. the only thing that that can't solve is cases where the Cy*K term ends in .25, but there are no solutions to that regardless since none of the other term can have increments smaller than .5 anyways

hobbesmaster
Jan 28, 2008

since when have MS compilers complained about iterators?

warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'

this is because the c++ standards people laughed at MS trying to get them to put in snprintf_s and stuff right. (because passing in two n's instead of one n will make sure its safe!)

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

hobbesmaster posted:

-D_SCL_SECURE_NO_WARNINGS

this directive seems both oddly familiar and ominous, but i can't place it exactly... i think the warning might only come up when dealing with libraries that were compiled with different settings than the ones used in the project importing them or something? it would explain the feeling of unspecified dread i currently have if it was responsible for one of the times i had to go through a bunch of dependencies and manually recompile every single one of them to reconcile their settings with the hosed up project configuration we used at a previous job

hobbesmaster
Jan 28, 2008

its just the iterator counterpart to _CRT_SECURE_NO_WARNINGS

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal
i must be thinking of a different thing then

Bloody
Mar 3, 2013

YeOldeButchere posted:

that seems like it would work, since the problem is a lot simpler with 0 as being part of the valid range. the only thing that that can't solve is cases where the Cy*K term ends in .25, but there are no solutions to that regardless since none of the other term can have increments smaller than .5 anyways

if K = 4, Cy = 20, and Cx = 10:
Ay = 80
Ax = 2.5

hence the need for Bx/By:
Ay = 40
Ax = 3
By = 40
Bx = 2

HoboMan
Nov 4, 2010

hmm, i realize don't know how to do math anymore without both mathematica and matlab at my disposal

comedyblissoption
Mar 15, 2006

HoboMan posted:

no variable declarations! this is good i swear! no it's not confusing you see because the scope will be obvious from context!
you just need to look at the entire possible scope that a variable binding could be referenced every single time you use a variable! what's the big deal???

other langs like python notably also make this mistake

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

hobbesmaster posted:

(because passing in two n's instead of one n will make sure its safe!)

all the _s string functions replace a single char * argument (an unbound buffer) with a pair of a char * and a size_t. think of the pair of arguments as a structure that describes a buffer, except instead of a structure you pass the fields one by one. the count argument stays because you don't necessarily want to fill the buffer (and an easy way to fill the buffer is to pass special value _TRUNCATE). conceptually speaking

this is for ease of code auditing I guess, both auditing pre-_s code to easily upgrade it, and auditing _s code for correctness. you'll remember those functions came out of the massive windows xp sp2 audit, try to imagine just how much loving code they were supposed to audit and what a godsend is it to, say, look up the declaration of the buffer variable, find the buffer size declared nearby and knowing you can safely use that value blindly, without understanding what the code does. say there's a condition when count comes out larger than the buffer, because a buggy calculation that should return a smaller value than the buffer size sometimes overflows or underflows: regular snprintf would overflow the buffer and then who knows what happens next, _snprintf_s will call the invalid parameter handler and either terminate the process or return an error. C programmers hate correctness, they like to overflow buffers. I tried enabling address sanitizer on our product once, and two distinct third party libraries read beyond the end of statically declared variables, because it's "harmless". see also the linux kernel where people do range checking by comparing the addresses of two distinct arrays and the compiler goes "these two arrays don't overlap in any way I'll just delete the check" (the linker makes the arrays overlap but can't tell the compiler)

std::copy is, in fact, unsafe, because the output range is unbound. this is only safe if the output is an output iterator (like say an iterator adapter over I/O, or an inserting iterator)

hackbunny fucked around with this message at 00:45 on Jul 23, 2016

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

comedyblissoption posted:

you just need to look at the entire possible scope that a variable binding could be referenced every single time you use a variable! what's the big deal???

other langs like python notably also make this mistake

python 3's nonlocal is a delightfully succinct example of why not having variable declarations is dumb

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
.

hobbesmaster
Jan 28, 2008

hackbunny posted:

all the _s string functions replace a single char * argument (an unbound buffer) with a pair of a char * and a size_t. think of the pair of arguments as a structure that describes a buffer, except instead of a structure you pass the fields one by one. the count argument stays because you don't necessarily want to fill the buffer. conceptually speaking

this is for ease of code auditing I guess, both auditing pre-_s code to easily upgrade it, and auditing _s code for correctness. you'll remember those functions came out of the massive windows xp sp2 audit, try to imagine just how much loving code they were supposed to audit and what a godsend is it to, say, look up the declaration of the buffer variable, find the buffer size declared nearby and knowing you can safely use that value blindly, without understanding what the code does

std::copy is, in fact, unsafe, because the output range is unbound. this is only safe if the output is an output iterator (like say an iterator adapter over I/O, or an inserting iterator)

none of c or c++ is safe

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

hobbesmaster posted:

none of c or c++ is safe

show me the operating system not written in c or c++ :shrug:

hobbesmaster
Jan 28, 2008

like, microsoft has warnings in its compiler that amount to "oh my god you're writing cross platform C or C++!"

no poo poo, its a C++ compiler, you don't have to warn me that i'm compiling C++

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
would you believe that the major objection against standardization of _s functions is that you can't prove they're more secure

hobbesmaster
Jan 28, 2008

right because if you overrun in snprintf it'd be exactly the same in snprintf_s because you were wrong about the size of your buffer

jony neuemonic
Nov 13, 2009

hackbunny posted:

show me the operating system not written in c or c++ :shrug:

well, okay.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

hobbesmaster posted:

right because if you overrun in snprintf it'd be exactly the same in snprintf_s because you were wrong about the size of your buffer

see? you're one of them

no, buffers don't come out of nowhere, they are allocated. take the allocation size, or the array magnitude, that's super easy to look up in the code. snprintf conflates size of the output with size of the buffer. the nearly mechanical translation from snprintf to snprintf_s consists of taking the exact value passed to malloc or whatever, and passing it as the buffer size, and leaving the string size argument unchanged. maybe it turns out you're passing the same value twice, maybe not. in the cases where it's not, you may have fixed a bug. snprintf_s is even designed so that it won't be fixed silently, it will make sure you'll notice if you hit a case that would have overflowed with the old code

these are weird and silly objections, _s functions were designed for upgrading existing codebases easily, not for "elegant" code (gently caress elegant code tbh). they come from the audit of a real world project (a Goddamn operating system I might add) and this should be considered a huge plus but somehow it isn't. hey what if %n has no conceivable use outside of malicious stack corruption, you'll make it opt-in over my cold dead body

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

Bloody posted:

if K = 4, Cy = 20, and Cx = 10:
Ay = 80
Ax = 2.5

hence the need for Bx/By:
Ay = 40
Ax = 3
By = 40
Bx = 2

welp i'm an idiot

the worst part of this is that i know i've seen stuff like that in undergrad, especially in the third algorithms and data structures course where a huge part of it was linear programming and other optimization problems, and how most of it is np but some can be approximated within a known bound. this totally feels like an assignment question and it pisses me off that i can't answer it!

Adbot
ADBOT LOVES YOU

Bloody
Mar 3, 2013

I think the answer involves taking the floor and ceiling of Cy / K and using them as Ax and Bx and then calculating appropriate Ay and By given those Ax and Bx

  • Locked thread