POV-Ray : Newsgroups : povray.general : select, is this logical? Server Time
25 Nov 2024 01:27:34 EST (-0500)
  select, is this logical? (Message 1 to 7 of 7)  
From: John Greenwood
Subject: select, is this logical?
Date: 3 Oct 2016 08:10:00
Message: <web.57f249b74d2b4fa1a7cafab50@news.povray.org>
The first parameter of the select function acts as a logic switch but does not
respond correctly to a boolean variable, thus

  #declare Change = true;
  #declare Function = function( F){select(Change,F,-F)}

gives the same result for Change = false

  #declare Function = function( F){select(-Change,F,-F)}

works.

This is not consistant, but I suppose we are stuck with it.


Post a reply to this message

From: William F Pokorny
Subject: Re: select, is this logical?
Date: 3 Oct 2016 09:30:45
Message: <57f25d85$1@news.povray.org>
On 10/03/2016 08:06 AM, John Greenwood wrote:
> The first parameter of the select function acts as a logic switch but does not
> respond correctly to a boolean variable, thus
>
>   #declare Change = true;
>   #declare Function = function( F){select(Change,F,-F)}
>
> gives the same result for Change = false
>
>   #declare Function = function( F){select(-Change,F,-F)}
>
> works.
>
> This is not consistant, but I suppose we are stuck with it.
>
>

Note there are two select variants. One with the traditional two options 
you not above and a second with three select options of negative, zero 
and positive. It is this latter form you want to use if your test 
returns a boolean result.

I too trip over the behavior on occasion which is documented at:

  http://wiki.povray.org/content/Reference:Numeric_Expressions#Functions

Supposing to answer for those smarter than me who architect-ed the 
current behavior, I believe the idea was to go with a default select 
operation which would work first with the bulk of the built in functions 
which tend to always transition through zero.

Then a second form which supports both such transitions and the boolean 
form.

In other words, I think they were first considering things from a 
mathematical view as opposed to a programming one.

Bill P.


Post a reply to this message

From: Bald Eagle
Subject: Re: select, is this logical?
Date: 3 Oct 2016 10:15:00
Message: <web.57f2672ddf9cd0bfb488d9aa0@news.povray.org>
William F Pokorny <ano### [at] anonymousorg> wrote:
> On 10/03/2016 08:06 AM, John Greenwood wrote:

> >   #declare Change = true;
> >   #declare Function = function( F){select(Change,F,-F)}

> Note there are two select variants. ....
> Then a second form which supports both such transitions and the boolean
> form.


So, the thing(s) to try would be:

#declare Change = true;
#declare Function = function (F) { select(Change, F, F, -F) }

or

#declare Function = function (F) { select(Change, F, -F, -F) }

Correct?


Post a reply to this message

From: William F Pokorny
Subject: Re: select, is this logical?
Date: 3 Oct 2016 11:34:24
Message: <57f27a80$1@news.povray.org>
On 10/03/2016 10:11 AM, Bald Eagle wrote:
> William F Pokorny <ano### [at] anonymousorg> wrote:
>> On 10/03/2016 08:06 AM, John Greenwood wrote:
>
>>>   #declare Change = true;
>>>   #declare Function = function( F){select(Change,F,-F)}
>
>> Note there are two select variants. ....
>> Then a second form which supports both such transitions and the boolean
>> form.
>
>
> So, the thing(s) to try would be:
>
> #declare Change = true;
> #declare Function = function (F) { select(Change, F, F, -F) }
>
> or
>
> #declare Function = function (F) { select(Change, F, -F, -F) }
>
> Correct?
>
>

The 'boolean' returns 0 or 1 and so triggers only the last two of the 
negative, zero or positive selections in order.

Perhaps play with this code:

#version 3.7;
global_settings { assumed_gamma 1 }
#include "functions.inc"
#debug "\n---\n"
#debug concat("select((1<0),-1.0,0.0,1.0) ==> ",
        str(select((1<0),-1.0,0.0,1.0),0,4)," \n")
#debug concat("select(false,-1.0,0.0,1.0) ==> ",
        str(select(false,-1.0,0.0,1.0),0,4)," \n")
#debug concat("select((1>0),-1.0,0.0,1.0) ==> ",
        str(select((1>0),-1.0,0.0,1.0),0,4)," \n")
#debug concat("select(true,-1.0,0.0,1.0)  ==> ",
        str(select(true,-1.0,0.0,1.0),0,4)," \n")
#debug concat("select(-1,-1.0,0.0,1.0)    ==> ",
        str(select(-1,-1.0,0.0,1.0),0,4)," \n")
#debug "---\n"
#error "Stop before actual render for demonstration code."


Bill P.


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: select, is this logical?
Date: 3 Oct 2016 15:30:01
Message: <web.57f2b108df9cd0bfde6f60b40@news.povray.org>
"John Greenwood" <joh### [at] john-greenwoodcouk> wrote:
> The first parameter of the select function acts as a logic switch but does not
> respond correctly to a boolean variable, thus

This is *what you think* it does, but it is not meant to be a logical switch. It
is a mathematical selection, where two or three specific conditions matter in
functions. Please go and read the manual before you complain about behavior you
just don't understand!

BTW, you can get *what you want* with just a simple mathematical expression,
without any function. How to do that is left as an exercise to the reader.


Post a reply to this message

From: clipka
Subject: Re: select, is this logical?
Date: 3 Oct 2016 17:38:10
Message: <57f2cfc2$1@news.povray.org>
Am 03.10.2016 um 14:06 schrieb John Greenwood:
> The first parameter of the select function acts as a logic switch

No, it absolutely positively does _not_.

The select function acts as a _threshold_ switch, forming an
indispensible basic building block for piecewise-defined functions.

> but does not
> respond correctly to a boolean variable, thus
> 
>   #declare Change = true;
>   #declare Function = function( F){select(Change,F,-F)}
> 
> gives the same result for Change = false
> 
>   #declare Function = function( F){select(-Change,F,-F)}
> 
> works.
> 
> This is not consistant, but I suppose we are stuck with it.

With the `select()` function implemented as a threshold switch, there
would be _no way whatsoever_ to have it also behave consistently as a
boolean switch. Remember that wherever a boolean is expected, _any_
non-zero value is interpreted as `true`, not just positive values.

So in a way it is rather fortunate that `select()` behaviour does _not_
happen to match the behaviour expected of a boolean switch for both
`true` and `false` input values, as that might lead people to
erroneously expect boolean switch behaviour for other input values as
well where it absolutely positively cannot be supported.


Post a reply to this message

From: John Greenwood
Subject: Re: select, is this logical?
Date: 4 Oct 2016 05:00:01
Message: <web.57f36e83df9cd0bfa7cafab50@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 03.10.2016 um 14:06 schrieb John Greenwood:
> > The first parameter of the select function acts as a logic switch
>
> No, it absolutely positively does _not_.
> With the `select()` function implemented as a threshold switch, there
> would be _no way whatsoever_ to have it also behave consistently as a
> boolean switch. Remember that wherever a boolean is expected, _any_
> non-zero value is interpreted as `true`, not just positive values.
>
> So in a way it is rather fortunate that `select()` behaviour does _not_
> happen to match the behaviour expected of a boolean switch for both
> `true` and `false` input values, as that might lead people to
> erroneously expect boolean switch behaviour for other input values as
> well where it absolutely positively cannot be supported.

Ah. I understand. Thanks for the clear explanation.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.