Disney BSSRDF, sample scattering profile, upper

Percentage Accurate: 95.9% → 97.9%
Time: 6.0s
Alternatives: 4
Speedup: 1.2×

Specification

?
\[\left(0 \leq s \land s \leq 256\right) \land \left(0.25 \leq u \land u \leq 1\right)\]
\[\begin{array}{l} \\ \left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \end{array} \]
(FPCore (s u)
 :precision binary32
 (* (* 3.0 s) (log (/ 1.0 (- 1.0 (/ (- u 0.25) 0.75))))))
float code(float s, float u) {
	return (3.0f * s) * logf((1.0f / (1.0f - ((u - 0.25f) / 0.75f))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(s, u)
use fmin_fmax_functions
    real(4), intent (in) :: s
    real(4), intent (in) :: u
    code = (3.0e0 * s) * log((1.0e0 / (1.0e0 - ((u - 0.25e0) / 0.75e0))))
end function
function code(s, u)
	return Float32(Float32(Float32(3.0) * s) * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(u - Float32(0.25)) / Float32(0.75))))))
end
function tmp = code(s, u)
	tmp = (single(3.0) * s) * log((single(1.0) / (single(1.0) - ((u - single(0.25)) / single(0.75)))));
end
\begin{array}{l}

\\
\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)
\end{array}

Sampling outcomes in binary32 precision:

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: 95.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \end{array} \]
(FPCore (s u)
 :precision binary32
 (* (* 3.0 s) (log (/ 1.0 (- 1.0 (/ (- u 0.25) 0.75))))))
float code(float s, float u) {
	return (3.0f * s) * logf((1.0f / (1.0f - ((u - 0.25f) / 0.75f))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(s, u)
use fmin_fmax_functions
    real(4), intent (in) :: s
    real(4), intent (in) :: u
    code = (3.0e0 * s) * log((1.0e0 / (1.0e0 - ((u - 0.25e0) / 0.75e0))))
end function
function code(s, u)
	return Float32(Float32(Float32(3.0) * s) * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(u - Float32(0.25)) / Float32(0.75))))))
end
function tmp = code(s, u)
	tmp = (single(3.0) * s) * log((single(1.0) / (single(1.0) - ((u - single(0.25)) / single(0.75)))));
end
\begin{array}{l}

\\
\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)
\end{array}

Alternative 1: 97.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \left(\mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right) \cdot -3\right) \cdot s \end{array} \]
(FPCore (s u)
 :precision binary32
 (* (* (log1p (fma -1.3333333333333333 u 0.3333333333333333)) -3.0) s))
float code(float s, float u) {
	return (log1pf(fmaf(-1.3333333333333333f, u, 0.3333333333333333f)) * -3.0f) * s;
}
function code(s, u)
	return Float32(Float32(log1p(fma(Float32(-1.3333333333333333), u, Float32(0.3333333333333333))) * Float32(-3.0)) * s)
end
\begin{array}{l}

\\
\left(\mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right) \cdot -3\right) \cdot s
\end{array}
Derivation
  1. Initial program 95.9%

    \[\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \]
  2. Add Preprocessing
  3. Taylor expanded in s around 0

    \[\leadsto \color{blue}{3 \cdot \left(s \cdot \log \left(\frac{1}{1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)}\right)\right)} \]
  4. Step-by-step derivation
    1. associate-*r*N/A

      \[\leadsto \color{blue}{\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)}\right)} \]
    2. log-recN/A

      \[\leadsto \left(3 \cdot s\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right)\right)\right)} \]
    3. distribute-rgt-neg-outN/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(\left(3 \cdot s\right) \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right)\right)} \]
    4. distribute-lft-neg-inN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(3 \cdot s\right)\right) \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right)} \]
    5. distribute-lft-neg-outN/A

      \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(3\right)\right) \cdot s\right)} \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right) \]
    6. metadata-evalN/A

      \[\leadsto \left(\color{blue}{-3} \cdot s\right) \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right) \]
    7. lower-*.f32N/A

      \[\leadsto \color{blue}{\left(-3 \cdot s\right) \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right)} \]
    8. lower-*.f32N/A

      \[\leadsto \color{blue}{\left(-3 \cdot s\right)} \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right) \]
    9. fp-cancel-sub-sign-invN/A

      \[\leadsto \left(-3 \cdot s\right) \cdot \log \color{blue}{\left(1 + \left(\mathsf{neg}\left(\frac{4}{3}\right)\right) \cdot \left(u - \frac{1}{4}\right)\right)} \]
    10. lower-log1p.f32N/A

      \[\leadsto \left(-3 \cdot s\right) \cdot \color{blue}{\mathsf{log1p}\left(\left(\mathsf{neg}\left(\frac{4}{3}\right)\right) \cdot \left(u - \frac{1}{4}\right)\right)} \]
    11. metadata-evalN/A

      \[\leadsto \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\color{blue}{\frac{-4}{3}} \cdot \left(u - \frac{1}{4}\right)\right) \]
    12. lower-*.f32N/A

      \[\leadsto \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\color{blue}{\frac{-4}{3} \cdot \left(u - \frac{1}{4}\right)}\right) \]
    13. lower--.f3297.8

      \[\leadsto \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(-1.3333333333333333 \cdot \color{blue}{\left(u - 0.25\right)}\right) \]
  5. Applied rewrites97.8%

    \[\leadsto \color{blue}{\left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(-1.3333333333333333 \cdot \left(u - 0.25\right)\right)} \]
  6. Step-by-step derivation
    1. Applied rewrites97.9%

      \[\leadsto \left(\mathsf{log1p}\left(\left(u - 0.25\right) \cdot -1.3333333333333333\right) \cdot -3\right) \cdot \color{blue}{s} \]
    2. Taylor expanded in u around 0

      \[\leadsto \left(\mathsf{log1p}\left(\frac{1}{3} + \frac{-4}{3} \cdot u\right) \cdot -3\right) \cdot s \]
    3. Step-by-step derivation
      1. Applied rewrites97.9%

        \[\leadsto \left(\mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right) \cdot -3\right) \cdot s \]
      2. Add Preprocessing

      Alternative 2: 97.9% accurate, 1.2× speedup?

      \[\begin{array}{l} \\ \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right) \end{array} \]
      (FPCore (s u)
       :precision binary32
       (* (* -3.0 s) (log1p (fma -1.3333333333333333 u 0.3333333333333333))))
      float code(float s, float u) {
      	return (-3.0f * s) * log1pf(fmaf(-1.3333333333333333f, u, 0.3333333333333333f));
      }
      
      function code(s, u)
      	return Float32(Float32(Float32(-3.0) * s) * log1p(fma(Float32(-1.3333333333333333), u, Float32(0.3333333333333333))))
      end
      
      \begin{array}{l}
      
      \\
      \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right)
      \end{array}
      
      Derivation
      1. Initial program 95.9%

        \[\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \]
      2. Add Preprocessing
      3. Taylor expanded in s around 0

        \[\leadsto \color{blue}{3 \cdot \left(s \cdot \log \left(\frac{1}{1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)}\right)\right)} \]
      4. Step-by-step derivation
        1. associate-*r*N/A

          \[\leadsto \color{blue}{\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)}\right)} \]
        2. log-recN/A

          \[\leadsto \left(3 \cdot s\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right)\right)\right)} \]
        3. distribute-rgt-neg-outN/A

          \[\leadsto \color{blue}{\mathsf{neg}\left(\left(3 \cdot s\right) \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right)\right)} \]
        4. distribute-lft-neg-inN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(3 \cdot s\right)\right) \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right)} \]
        5. distribute-lft-neg-outN/A

          \[\leadsto \color{blue}{\left(\left(\mathsf{neg}\left(3\right)\right) \cdot s\right)} \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right) \]
        6. metadata-evalN/A

          \[\leadsto \left(\color{blue}{-3} \cdot s\right) \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right) \]
        7. lower-*.f32N/A

          \[\leadsto \color{blue}{\left(-3 \cdot s\right) \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right)} \]
        8. lower-*.f32N/A

          \[\leadsto \color{blue}{\left(-3 \cdot s\right)} \cdot \log \left(1 - \frac{4}{3} \cdot \left(u - \frac{1}{4}\right)\right) \]
        9. fp-cancel-sub-sign-invN/A

          \[\leadsto \left(-3 \cdot s\right) \cdot \log \color{blue}{\left(1 + \left(\mathsf{neg}\left(\frac{4}{3}\right)\right) \cdot \left(u - \frac{1}{4}\right)\right)} \]
        10. lower-log1p.f32N/A

          \[\leadsto \left(-3 \cdot s\right) \cdot \color{blue}{\mathsf{log1p}\left(\left(\mathsf{neg}\left(\frac{4}{3}\right)\right) \cdot \left(u - \frac{1}{4}\right)\right)} \]
        11. metadata-evalN/A

          \[\leadsto \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\color{blue}{\frac{-4}{3}} \cdot \left(u - \frac{1}{4}\right)\right) \]
        12. lower-*.f32N/A

          \[\leadsto \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\color{blue}{\frac{-4}{3} \cdot \left(u - \frac{1}{4}\right)}\right) \]
        13. lower--.f3297.8

          \[\leadsto \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(-1.3333333333333333 \cdot \color{blue}{\left(u - 0.25\right)}\right) \]
      5. Applied rewrites97.8%

        \[\leadsto \color{blue}{\left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(-1.3333333333333333 \cdot \left(u - 0.25\right)\right)} \]
      6. Taylor expanded in u around 0

        \[\leadsto \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\frac{1}{3} + \frac{-4}{3} \cdot u\right) \]
      7. Step-by-step derivation
        1. Applied rewrites97.8%

          \[\leadsto \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right) \]
        2. Final simplification97.8%

          \[\leadsto \left(-3 \cdot s\right) \cdot \mathsf{log1p}\left(\mathsf{fma}\left(-1.3333333333333333, u, 0.3333333333333333\right)\right) \]
        3. Add Preprocessing

        Alternative 3: 25.7% accurate, 1.2× speedup?

        \[\begin{array}{l} \\ \mathsf{fma}\left(u, 3, \log 0.421875\right) \cdot s \end{array} \]
        (FPCore (s u) :precision binary32 (* (fma u 3.0 (log 0.421875)) s))
        float code(float s, float u) {
        	return fmaf(u, 3.0f, logf(0.421875f)) * s;
        }
        
        function code(s, u)
        	return Float32(fma(u, Float32(3.0), log(Float32(0.421875))) * s)
        end
        
        \begin{array}{l}
        
        \\
        \mathsf{fma}\left(u, 3, \log 0.421875\right) \cdot s
        \end{array}
        
        Derivation
        1. Initial program 95.9%

          \[\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto \color{blue}{\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)} \]
          2. *-commutativeN/A

            \[\leadsto \color{blue}{\log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right) \cdot \left(3 \cdot s\right)} \]
          3. lift-*.f32N/A

            \[\leadsto \log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right) \cdot \color{blue}{\left(3 \cdot s\right)} \]
          4. associate-*r*N/A

            \[\leadsto \color{blue}{\left(\log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right) \cdot 3\right) \cdot s} \]
          5. lower-*.f32N/A

            \[\leadsto \color{blue}{\left(\log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right) \cdot 3\right) \cdot s} \]
          6. lower-*.f3295.8

            \[\leadsto \color{blue}{\left(\log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \cdot 3\right)} \cdot s \]
          7. lift-log.f32N/A

            \[\leadsto \left(\color{blue}{\log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)} \cdot 3\right) \cdot s \]
          8. lift-/.f32N/A

            \[\leadsto \left(\log \color{blue}{\left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)} \cdot 3\right) \cdot s \]
          9. log-recN/A

            \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)\right)\right)} \cdot 3\right) \cdot s \]
          10. lower-neg.f32N/A

            \[\leadsto \left(\color{blue}{\left(-\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)\right)} \cdot 3\right) \cdot s \]
          11. lower-log.f3296.6

            \[\leadsto \left(\left(-\color{blue}{\log \left(1 - \frac{u - 0.25}{0.75}\right)}\right) \cdot 3\right) \cdot s \]
        4. Applied rewrites96.6%

          \[\leadsto \color{blue}{\left(\left(-\log \left(1 - \frac{u - 0.25}{0.75}\right)\right) \cdot 3\right) \cdot s} \]
        5. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto \color{blue}{\left(\left(-\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)\right) \cdot 3\right)} \cdot s \]
          2. *-commutativeN/A

            \[\leadsto \color{blue}{\left(3 \cdot \left(-\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)\right)\right)} \cdot s \]
          3. lift-neg.f32N/A

            \[\leadsto \left(3 \cdot \color{blue}{\left(\mathsf{neg}\left(\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)\right)\right)}\right) \cdot s \]
          4. lift-log.f32N/A

            \[\leadsto \left(3 \cdot \left(\mathsf{neg}\left(\color{blue}{\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)}\right)\right)\right) \cdot s \]
          5. neg-logN/A

            \[\leadsto \left(3 \cdot \color{blue}{\log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)}\right) \cdot s \]
          6. lift--.f32N/A

            \[\leadsto \left(3 \cdot \log \left(\frac{1}{\color{blue}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}}\right)\right) \cdot s \]
          7. lift-/.f32N/A

            \[\leadsto \left(3 \cdot \log \left(\frac{1}{1 - \color{blue}{\frac{u - \frac{1}{4}}{\frac{3}{4}}}}\right)\right) \cdot s \]
          8. lift--.f32N/A

            \[\leadsto \left(3 \cdot \log \left(\frac{1}{1 - \frac{\color{blue}{u - \frac{1}{4}}}{\frac{3}{4}}}\right)\right) \cdot s \]
          9. log-pow-revN/A

            \[\leadsto \color{blue}{\log \left({\left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)}^{3}\right)} \cdot s \]
          10. lower-log.f32N/A

            \[\leadsto \color{blue}{\log \left({\left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)}^{3}\right)} \cdot s \]
          11. lower-pow.f32N/A

            \[\leadsto \log \color{blue}{\left({\left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)}^{3}\right)} \cdot s \]
          12. lift--.f32N/A

            \[\leadsto \log \left({\left(\frac{1}{1 - \frac{\color{blue}{u - \frac{1}{4}}}{\frac{3}{4}}}\right)}^{3}\right) \cdot s \]
          13. lift-/.f32N/A

            \[\leadsto \log \left({\left(\frac{1}{1 - \color{blue}{\frac{u - \frac{1}{4}}{\frac{3}{4}}}}\right)}^{3}\right) \cdot s \]
          14. lift--.f32N/A

            \[\leadsto \log \left({\left(\frac{1}{\color{blue}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}}\right)}^{3}\right) \cdot s \]
          15. lower-/.f3295.9

            \[\leadsto \log \left({\color{blue}{\left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)}}^{3}\right) \cdot s \]
        6. Applied rewrites95.9%

          \[\leadsto \color{blue}{\log \left({\left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)}^{3}\right)} \cdot s \]
        7. Taylor expanded in u around 0

          \[\leadsto \color{blue}{\left(\log \frac{27}{64} + 3 \cdot u\right)} \cdot s \]
        8. Step-by-step derivation
          1. +-commutativeN/A

            \[\leadsto \color{blue}{\left(3 \cdot u + \log \frac{27}{64}\right)} \cdot s \]
          2. *-commutativeN/A

            \[\leadsto \left(\color{blue}{u \cdot 3} + \log \frac{27}{64}\right) \cdot s \]
          3. lower-fma.f32N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(u, 3, \log \frac{27}{64}\right)} \cdot s \]
          4. lower-log.f3226.1

            \[\leadsto \mathsf{fma}\left(u, 3, \color{blue}{\log 0.421875}\right) \cdot s \]
        9. Applied rewrites26.1%

          \[\leadsto \color{blue}{\mathsf{fma}\left(u, 3, \log 0.421875\right)} \cdot s \]
        10. Add Preprocessing

        Alternative 4: 7.3% accurate, 1.3× speedup?

        \[\begin{array}{l} \\ \log 0.421875 \cdot s \end{array} \]
        (FPCore (s u) :precision binary32 (* (log 0.421875) s))
        float code(float s, float u) {
        	return logf(0.421875f) * s;
        }
        
        module fmin_fmax_functions
            implicit none
            private
            public fmax
            public fmin
        
            interface fmax
                module procedure fmax88
                module procedure fmax44
                module procedure fmax84
                module procedure fmax48
            end interface
            interface fmin
                module procedure fmin88
                module procedure fmin44
                module procedure fmin84
                module procedure fmin48
            end interface
        contains
            real(8) function fmax88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(4) function fmax44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(8) function fmax84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmax48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
            end function
            real(8) function fmin88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(4) function fmin44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(8) function fmin84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmin48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
            end function
        end module
        
        real(4) function code(s, u)
        use fmin_fmax_functions
            real(4), intent (in) :: s
            real(4), intent (in) :: u
            code = log(0.421875e0) * s
        end function
        
        function code(s, u)
        	return Float32(log(Float32(0.421875)) * s)
        end
        
        function tmp = code(s, u)
        	tmp = log(single(0.421875)) * s;
        end
        
        \begin{array}{l}
        
        \\
        \log 0.421875 \cdot s
        \end{array}
        
        Derivation
        1. Initial program 95.9%

          \[\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto \color{blue}{\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)} \]
          2. *-commutativeN/A

            \[\leadsto \color{blue}{\log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right) \cdot \left(3 \cdot s\right)} \]
          3. lift-*.f32N/A

            \[\leadsto \log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right) \cdot \color{blue}{\left(3 \cdot s\right)} \]
          4. associate-*r*N/A

            \[\leadsto \color{blue}{\left(\log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right) \cdot 3\right) \cdot s} \]
          5. lower-*.f32N/A

            \[\leadsto \color{blue}{\left(\log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right) \cdot 3\right) \cdot s} \]
          6. lower-*.f3295.8

            \[\leadsto \color{blue}{\left(\log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \cdot 3\right)} \cdot s \]
          7. lift-log.f32N/A

            \[\leadsto \left(\color{blue}{\log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)} \cdot 3\right) \cdot s \]
          8. lift-/.f32N/A

            \[\leadsto \left(\log \color{blue}{\left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)} \cdot 3\right) \cdot s \]
          9. log-recN/A

            \[\leadsto \left(\color{blue}{\left(\mathsf{neg}\left(\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)\right)\right)} \cdot 3\right) \cdot s \]
          10. lower-neg.f32N/A

            \[\leadsto \left(\color{blue}{\left(-\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)\right)} \cdot 3\right) \cdot s \]
          11. lower-log.f3296.6

            \[\leadsto \left(\left(-\color{blue}{\log \left(1 - \frac{u - 0.25}{0.75}\right)}\right) \cdot 3\right) \cdot s \]
        4. Applied rewrites96.6%

          \[\leadsto \color{blue}{\left(\left(-\log \left(1 - \frac{u - 0.25}{0.75}\right)\right) \cdot 3\right) \cdot s} \]
        5. Step-by-step derivation
          1. lift-*.f32N/A

            \[\leadsto \color{blue}{\left(\left(-\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)\right) \cdot 3\right)} \cdot s \]
          2. *-commutativeN/A

            \[\leadsto \color{blue}{\left(3 \cdot \left(-\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)\right)\right)} \cdot s \]
          3. lift-neg.f32N/A

            \[\leadsto \left(3 \cdot \color{blue}{\left(\mathsf{neg}\left(\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)\right)\right)}\right) \cdot s \]
          4. lift-log.f32N/A

            \[\leadsto \left(3 \cdot \left(\mathsf{neg}\left(\color{blue}{\log \left(1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}\right)}\right)\right)\right) \cdot s \]
          5. neg-logN/A

            \[\leadsto \left(3 \cdot \color{blue}{\log \left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)}\right) \cdot s \]
          6. lift--.f32N/A

            \[\leadsto \left(3 \cdot \log \left(\frac{1}{\color{blue}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}}\right)\right) \cdot s \]
          7. lift-/.f32N/A

            \[\leadsto \left(3 \cdot \log \left(\frac{1}{1 - \color{blue}{\frac{u - \frac{1}{4}}{\frac{3}{4}}}}\right)\right) \cdot s \]
          8. lift--.f32N/A

            \[\leadsto \left(3 \cdot \log \left(\frac{1}{1 - \frac{\color{blue}{u - \frac{1}{4}}}{\frac{3}{4}}}\right)\right) \cdot s \]
          9. log-pow-revN/A

            \[\leadsto \color{blue}{\log \left({\left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)}^{3}\right)} \cdot s \]
          10. lower-log.f32N/A

            \[\leadsto \color{blue}{\log \left({\left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)}^{3}\right)} \cdot s \]
          11. lower-pow.f32N/A

            \[\leadsto \log \color{blue}{\left({\left(\frac{1}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}\right)}^{3}\right)} \cdot s \]
          12. lift--.f32N/A

            \[\leadsto \log \left({\left(\frac{1}{1 - \frac{\color{blue}{u - \frac{1}{4}}}{\frac{3}{4}}}\right)}^{3}\right) \cdot s \]
          13. lift-/.f32N/A

            \[\leadsto \log \left({\left(\frac{1}{1 - \color{blue}{\frac{u - \frac{1}{4}}{\frac{3}{4}}}}\right)}^{3}\right) \cdot s \]
          14. lift--.f32N/A

            \[\leadsto \log \left({\left(\frac{1}{\color{blue}{1 - \frac{u - \frac{1}{4}}{\frac{3}{4}}}}\right)}^{3}\right) \cdot s \]
          15. lower-/.f3295.9

            \[\leadsto \log \left({\color{blue}{\left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)}}^{3}\right) \cdot s \]
        6. Applied rewrites95.9%

          \[\leadsto \color{blue}{\log \left({\left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)}^{3}\right)} \cdot s \]
        7. Taylor expanded in u around 0

          \[\leadsto \log \color{blue}{\frac{27}{64}} \cdot s \]
        8. Step-by-step derivation
          1. Applied rewrites7.7%

            \[\leadsto \log \color{blue}{0.421875} \cdot s \]
          2. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 2025015 
          (FPCore (s u)
            :name "Disney BSSRDF, sample scattering profile, upper"
            :precision binary32
            :pre (and (and (<= 0.0 s) (<= s 256.0)) (and (<= 0.25 u) (<= u 1.0)))
            (* (* 3.0 s) (log (/ 1.0 (- 1.0 (/ (- u 0.25) 0.75))))))