HairBSDF, Mp, upper

Percentage Accurate: 98.6% → 98.6%
Time: 9.8s
Alternatives: 4
Speedup: 1.0×

Specification

?
\[\left(\left(\left(\left(\left(-1 \leq cosTheta\_i \land cosTheta\_i \leq 1\right) \land \left(-1 \leq cosTheta\_O \land cosTheta\_O \leq 1\right)\right) \land \left(-1 \leq sinTheta\_i \land sinTheta\_i \leq 1\right)\right) \land \left(-1 \leq sinTheta\_O \land sinTheta\_O \leq 1\right)\right) \land 0.1 < v\right) \land v \leq 1.5707964\]
\[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
  :precision binary32
  (/
 (*
  (exp (- (/ (* sinTheta_i sinTheta_O) v)))
  (/ (* cosTheta_i cosTheta_O) v))
 (* (* (sinh (/ 1.0 v)) 2.0) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
	return (expf(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinhf((1.0f / v)) * 2.0f) * v);
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: costheta_o
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    code = (exp(-((sintheta_i * sintheta_o) / v)) * ((costheta_i * costheta_o) / v)) / ((sinh((1.0e0 / v)) * 2.0e0) * v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
	return Float32(Float32(exp(Float32(-Float32(Float32(sinTheta_i * sinTheta_O) / v))) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)) * v))
end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
	tmp = (exp(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinh((single(1.0) / v)) * single(2.0)) * v);
end
\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 4 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 98.6% accurate, 1.0× speedup?

\[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
  :precision binary32
  (/
 (*
  (exp (- (/ (* sinTheta_i sinTheta_O) v)))
  (/ (* cosTheta_i cosTheta_O) v))
 (* (* (sinh (/ 1.0 v)) 2.0) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
	return (expf(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinhf((1.0f / v)) * 2.0f) * v);
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: costheta_o
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    code = (exp(-((sintheta_i * sintheta_o) / v)) * ((costheta_i * costheta_o) / v)) / ((sinh((1.0e0 / v)) * 2.0e0) * v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
	return Float32(Float32(exp(Float32(-Float32(Float32(sinTheta_i * sinTheta_O) / v))) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)) * v))
end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
	tmp = (exp(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / ((sinh((single(1.0) / v)) * single(2.0)) * v);
end
\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v}

Alternative 1: 98.3% accurate, 1.5× speedup?

\[\frac{1 \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
(FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
  :precision binary32
  (/
 (* 1.0 (/ (* cosTheta_i cosTheta_O) v))
 (* (* (sinh (/ 1.0 v)) 2.0) v)))
float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
	return (1.0f * ((cosTheta_i * cosTheta_O) / v)) / ((sinhf((1.0f / v)) * 2.0f) * v);
}
real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
use fmin_fmax_functions
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: costheta_o
    real(4), intent (in) :: sintheta_i
    real(4), intent (in) :: sintheta_o
    real(4), intent (in) :: v
    code = (1.0e0 * ((costheta_i * costheta_o) / v)) / ((sinh((1.0e0 / v)) * 2.0e0) * v)
end function
function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
	return Float32(Float32(Float32(1.0) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) / Float32(Float32(sinh(Float32(Float32(1.0) / v)) * Float32(2.0)) * v))
end
function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
	tmp = (single(1.0) * ((cosTheta_i * cosTheta_O) / v)) / ((sinh((single(1.0) / v)) * single(2.0)) * v);
end
\frac{1 \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v}
Derivation
  1. Initial program 98.6%

    \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  2. Taylor expanded in sinTheta_i around 0

    \[\leadsto \frac{\color{blue}{1} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
  3. Step-by-step derivation
    1. Applied rewrites98.3%

      \[\leadsto \frac{\color{blue}{1} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    2. Add Preprocessing

    Alternative 2: 59.0% accurate, 1.7× speedup?

    \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{2} \]
    (FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
      :precision binary32
      (/
     (*
      (exp (- (/ (* sinTheta_i sinTheta_O) v)))
      (/ (* cosTheta_i cosTheta_O) v))
     2.0))
    float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
    	return (expf(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / 2.0f;
    }
    
    real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
    use fmin_fmax_functions
        real(4), intent (in) :: costheta_i
        real(4), intent (in) :: costheta_o
        real(4), intent (in) :: sintheta_i
        real(4), intent (in) :: sintheta_o
        real(4), intent (in) :: v
        code = (exp(-((sintheta_i * sintheta_o) / v)) * ((costheta_i * costheta_o) / v)) / 2.0e0
    end function
    
    function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
    	return Float32(Float32(exp(Float32(-Float32(Float32(sinTheta_i * sinTheta_O) / v))) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) / Float32(2.0))
    end
    
    function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
    	tmp = (exp(-((sinTheta_i * sinTheta_O) / v)) * ((cosTheta_i * cosTheta_O) / v)) / single(2.0);
    end
    
    \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{2}
    
    Derivation
    1. Initial program 98.6%

      \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
    2. Taylor expanded in v around inf

      \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\color{blue}{2}} \]
    3. Step-by-step derivation
      1. Applied rewrites59.0%

        \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\color{blue}{2}} \]
      2. Add Preprocessing

      Alternative 3: 59.0% accurate, 3.9× speedup?

      \[\frac{1 \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{2} \]
      (FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
        :precision binary32
        (/ (* 1.0 (/ (* cosTheta_i cosTheta_O) v)) 2.0))
      float code(float cosTheta_i, float cosTheta_O, float sinTheta_i, float sinTheta_O, float v) {
      	return (1.0f * ((cosTheta_i * cosTheta_O) / v)) / 2.0f;
      }
      
      real(4) function code(costheta_i, costheta_o, sintheta_i, sintheta_o, v)
      use fmin_fmax_functions
          real(4), intent (in) :: costheta_i
          real(4), intent (in) :: costheta_o
          real(4), intent (in) :: sintheta_i
          real(4), intent (in) :: sintheta_o
          real(4), intent (in) :: v
          code = (1.0e0 * ((costheta_i * costheta_o) / v)) / 2.0e0
      end function
      
      function code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
      	return Float32(Float32(Float32(1.0) * Float32(Float32(cosTheta_i * cosTheta_O) / v)) / Float32(2.0))
      end
      
      function tmp = code(cosTheta_i, cosTheta_O, sinTheta_i, sinTheta_O, v)
      	tmp = (single(1.0) * ((cosTheta_i * cosTheta_O) / v)) / single(2.0);
      end
      
      \frac{1 \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{2}
      
      Derivation
      1. Initial program 98.6%

        \[\frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\left(\sinh \left(\frac{1}{v}\right) \cdot 2\right) \cdot v} \]
      2. Taylor expanded in v around inf

        \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\color{blue}{2}} \]
      3. Step-by-step derivation
        1. Applied rewrites59.0%

          \[\leadsto \frac{e^{-\frac{sinTheta\_i \cdot sinTheta\_O}{v}} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{\color{blue}{2}} \]
        2. Taylor expanded in sinTheta_i around 0

          \[\leadsto \frac{\color{blue}{1} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{2} \]
        3. Step-by-step derivation
          1. Applied rewrites59.0%

            \[\leadsto \frac{\color{blue}{1} \cdot \frac{cosTheta\_i \cdot cosTheta\_O}{v}}{2} \]
          2. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 2025322 
          (FPCore (cosTheta_i cosTheta_O sinTheta_i sinTheta_O v)
            :name "HairBSDF, Mp, upper"
            :precision binary32
            :pre (and (and (and (and (and (and (<= -1.0 cosTheta_i) (<= cosTheta_i 1.0)) (and (<= -1.0 cosTheta_O) (<= cosTheta_O 1.0))) (and (<= -1.0 sinTheta_i) (<= sinTheta_i 1.0))) (and (<= -1.0 sinTheta_O) (<= sinTheta_O 1.0))) (< 0.1 v)) (<= v 1.5707964))
            (/ (* (exp (- (/ (* sinTheta_i sinTheta_O) v))) (/ (* cosTheta_i cosTheta_O) v)) (* (* (sinh (/ 1.0 v)) 2.0) v)))