Isotropic LOD (LOD)

Percentage Accurate: 53.2% → 53.2%
Time: 4.0s
Alternatives: 1
Speedup: 1.0×

Specification

?
\[\left(\left(\left(\left(\left(\left(\left(\left(1 \leq w \land w \leq 16384\right) \land \left(1 \leq h \land h \leq 16384\right)\right) \land \left(1 \leq d \land d \leq 4096\right)\right) \land \left(10^{-20} \leq \left|dX.u\right| \land \left|dX.u\right| \leq 10^{+20}\right)\right) \land \left(10^{-20} \leq \left|dX.v\right| \land \left|dX.v\right| \leq 10^{+20}\right)\right) \land \left(10^{-20} \leq \left|dX.w\right| \land \left|dX.w\right| \leq 10^{+20}\right)\right) \land \left(10^{-20} \leq \left|dY.u\right| \land \left|dY.u\right| \leq 10^{+20}\right)\right) \land \left(10^{-20} \leq \left|dY.v\right| \land \left|dY.v\right| \leq 10^{+20}\right)\right) \land \left(10^{-20} \leq \left|dY.w\right| \land \left|dY.w\right| \leq 10^{+20}\right)\]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left\lfloor w\right\rfloor \cdot dY.u\\ t_1 := \left\lfloor h\right\rfloor \cdot dY.v\\ t_2 := \left\lfloor h\right\rfloor \cdot dX.v\\ t_3 := \left\lfloor d\right\rfloor \cdot dY.w\\ t_4 := \left\lfloor d\right\rfloor \cdot dX.w\\ t_5 := \left\lfloor w\right\rfloor \cdot dX.u\\ \log_{2} \left(\sqrt{\mathsf{max}\left(\left(t\_5 \cdot t\_5 + t\_2 \cdot t\_2\right) + t\_4 \cdot t\_4, \left(t\_0 \cdot t\_0 + t\_1 \cdot t\_1\right) + t\_3 \cdot t\_3\right)}\right) \end{array} \end{array} \]
(FPCore (w h d dX.u dX.v dX.w dY.u dY.v dY.w)
 :precision binary32
 (let* ((t_0 (* (floor w) dY.u))
        (t_1 (* (floor h) dY.v))
        (t_2 (* (floor h) dX.v))
        (t_3 (* (floor d) dY.w))
        (t_4 (* (floor d) dX.w))
        (t_5 (* (floor w) dX.u)))
   (log2
    (sqrt
     (fmax
      (+ (+ (* t_5 t_5) (* t_2 t_2)) (* t_4 t_4))
      (+ (+ (* t_0 t_0) (* t_1 t_1)) (* t_3 t_3)))))))
float code(float w, float h, float d, float dX_46_u, float dX_46_v, float dX_46_w, float dY_46_u, float dY_46_v, float dY_46_w) {
	float t_0 = floorf(w) * dY_46_u;
	float t_1 = floorf(h) * dY_46_v;
	float t_2 = floorf(h) * dX_46_v;
	float t_3 = floorf(d) * dY_46_w;
	float t_4 = floorf(d) * dX_46_w;
	float t_5 = floorf(w) * dX_46_u;
	return log2f(sqrtf(fmaxf((((t_5 * t_5) + (t_2 * t_2)) + (t_4 * t_4)), (((t_0 * t_0) + (t_1 * t_1)) + (t_3 * t_3)))));
}
function code(w, h, d, dX_46_u, dX_46_v, dX_46_w, dY_46_u, dY_46_v, dY_46_w)
	t_0 = Float32(floor(w) * dY_46_u)
	t_1 = Float32(floor(h) * dY_46_v)
	t_2 = Float32(floor(h) * dX_46_v)
	t_3 = Float32(floor(d) * dY_46_w)
	t_4 = Float32(floor(d) * dX_46_w)
	t_5 = Float32(floor(w) * dX_46_u)
	return log2(sqrt(fmax(Float32(Float32(Float32(t_5 * t_5) + Float32(t_2 * t_2)) + Float32(t_4 * t_4)), Float32(Float32(Float32(t_0 * t_0) + Float32(t_1 * t_1)) + Float32(t_3 * t_3)))))
end
function tmp = code(w, h, d, dX_46_u, dX_46_v, dX_46_w, dY_46_u, dY_46_v, dY_46_w)
	t_0 = floor(w) * dY_46_u;
	t_1 = floor(h) * dY_46_v;
	t_2 = floor(h) * dX_46_v;
	t_3 = floor(d) * dY_46_w;
	t_4 = floor(d) * dX_46_w;
	t_5 = floor(w) * dX_46_u;
	tmp = log2(sqrt(max((((t_5 * t_5) + (t_2 * t_2)) + (t_4 * t_4)), (((t_0 * t_0) + (t_1 * t_1)) + (t_3 * t_3)))));
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left\lfloor w\right\rfloor  \cdot dY.u\\
t_1 := \left\lfloor h\right\rfloor  \cdot dY.v\\
t_2 := \left\lfloor h\right\rfloor  \cdot dX.v\\
t_3 := \left\lfloor d\right\rfloor  \cdot dY.w\\
t_4 := \left\lfloor d\right\rfloor  \cdot dX.w\\
t_5 := \left\lfloor w\right\rfloor  \cdot dX.u\\
\log_{2} \left(\sqrt{\mathsf{max}\left(\left(t\_5 \cdot t\_5 + t\_2 \cdot t\_2\right) + t\_4 \cdot t\_4, \left(t\_0 \cdot t\_0 + t\_1 \cdot t\_1\right) + t\_3 \cdot t\_3\right)}\right)
\end{array}
\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 1 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: 53.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left\lfloor w\right\rfloor \cdot dY.u\\ t_1 := \left\lfloor h\right\rfloor \cdot dY.v\\ t_2 := \left\lfloor h\right\rfloor \cdot dX.v\\ t_3 := \left\lfloor d\right\rfloor \cdot dY.w\\ t_4 := \left\lfloor d\right\rfloor \cdot dX.w\\ t_5 := \left\lfloor w\right\rfloor \cdot dX.u\\ \log_{2} \left(\sqrt{\mathsf{max}\left(\left(t\_5 \cdot t\_5 + t\_2 \cdot t\_2\right) + t\_4 \cdot t\_4, \left(t\_0 \cdot t\_0 + t\_1 \cdot t\_1\right) + t\_3 \cdot t\_3\right)}\right) \end{array} \end{array} \]
(FPCore (w h d dX.u dX.v dX.w dY.u dY.v dY.w)
 :precision binary32
 (let* ((t_0 (* (floor w) dY.u))
        (t_1 (* (floor h) dY.v))
        (t_2 (* (floor h) dX.v))
        (t_3 (* (floor d) dY.w))
        (t_4 (* (floor d) dX.w))
        (t_5 (* (floor w) dX.u)))
   (log2
    (sqrt
     (fmax
      (+ (+ (* t_5 t_5) (* t_2 t_2)) (* t_4 t_4))
      (+ (+ (* t_0 t_0) (* t_1 t_1)) (* t_3 t_3)))))))
float code(float w, float h, float d, float dX_46_u, float dX_46_v, float dX_46_w, float dY_46_u, float dY_46_v, float dY_46_w) {
	float t_0 = floorf(w) * dY_46_u;
	float t_1 = floorf(h) * dY_46_v;
	float t_2 = floorf(h) * dX_46_v;
	float t_3 = floorf(d) * dY_46_w;
	float t_4 = floorf(d) * dX_46_w;
	float t_5 = floorf(w) * dX_46_u;
	return log2f(sqrtf(fmaxf((((t_5 * t_5) + (t_2 * t_2)) + (t_4 * t_4)), (((t_0 * t_0) + (t_1 * t_1)) + (t_3 * t_3)))));
}
function code(w, h, d, dX_46_u, dX_46_v, dX_46_w, dY_46_u, dY_46_v, dY_46_w)
	t_0 = Float32(floor(w) * dY_46_u)
	t_1 = Float32(floor(h) * dY_46_v)
	t_2 = Float32(floor(h) * dX_46_v)
	t_3 = Float32(floor(d) * dY_46_w)
	t_4 = Float32(floor(d) * dX_46_w)
	t_5 = Float32(floor(w) * dX_46_u)
	return log2(sqrt(fmax(Float32(Float32(Float32(t_5 * t_5) + Float32(t_2 * t_2)) + Float32(t_4 * t_4)), Float32(Float32(Float32(t_0 * t_0) + Float32(t_1 * t_1)) + Float32(t_3 * t_3)))))
end
function tmp = code(w, h, d, dX_46_u, dX_46_v, dX_46_w, dY_46_u, dY_46_v, dY_46_w)
	t_0 = floor(w) * dY_46_u;
	t_1 = floor(h) * dY_46_v;
	t_2 = floor(h) * dX_46_v;
	t_3 = floor(d) * dY_46_w;
	t_4 = floor(d) * dX_46_w;
	t_5 = floor(w) * dX_46_u;
	tmp = log2(sqrt(max((((t_5 * t_5) + (t_2 * t_2)) + (t_4 * t_4)), (((t_0 * t_0) + (t_1 * t_1)) + (t_3 * t_3)))));
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left\lfloor w\right\rfloor  \cdot dY.u\\
t_1 := \left\lfloor h\right\rfloor  \cdot dY.v\\
t_2 := \left\lfloor h\right\rfloor  \cdot dX.v\\
t_3 := \left\lfloor d\right\rfloor  \cdot dY.w\\
t_4 := \left\lfloor d\right\rfloor  \cdot dX.w\\
t_5 := \left\lfloor w\right\rfloor  \cdot dX.u\\
\log_{2} \left(\sqrt{\mathsf{max}\left(\left(t\_5 \cdot t\_5 + t\_2 \cdot t\_2\right) + t\_4 \cdot t\_4, \left(t\_0 \cdot t\_0 + t\_1 \cdot t\_1\right) + t\_3 \cdot t\_3\right)}\right)
\end{array}
\end{array}

Alternative 1: 53.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := dY.v \cdot \left\lfloor h\right\rfloor \\ t_1 := dX.v \cdot \left\lfloor h\right\rfloor \\ t_2 := dY.u \cdot \left\lfloor w\right\rfloor \\ t_3 := dX.u \cdot \left\lfloor w\right\rfloor \\ t_4 := dX.w \cdot \left\lfloor d\right\rfloor \\ t_5 := dY.w \cdot \left\lfloor d\right\rfloor \\ \log_{2} \left(\sqrt{\mathsf{max}\left(t\_4 \cdot t\_4 + \left(t\_1 \cdot t\_1 + t\_3 \cdot t\_3\right), t\_5 \cdot t\_5 + \left(t\_0 \cdot t\_0 + t\_2 \cdot t\_2\right)\right)}\right) \end{array} \end{array} \]
(FPCore (w h d dX.u dX.v dX.w dY.u dY.v dY.w)
 :precision binary32
 (let* ((t_0 (* dY.v (floor h)))
        (t_1 (* dX.v (floor h)))
        (t_2 (* dY.u (floor w)))
        (t_3 (* dX.u (floor w)))
        (t_4 (* dX.w (floor d)))
        (t_5 (* dY.w (floor d))))
   (log2
    (sqrt
     (fmax
      (+ (* t_4 t_4) (+ (* t_1 t_1) (* t_3 t_3)))
      (+ (* t_5 t_5) (+ (* t_0 t_0) (* t_2 t_2))))))))
float code(float w, float h, float d, float dX_46_u, float dX_46_v, float dX_46_w, float dY_46_u, float dY_46_v, float dY_46_w) {
	float t_0 = dY_46_v * floorf(h);
	float t_1 = dX_46_v * floorf(h);
	float t_2 = dY_46_u * floorf(w);
	float t_3 = dX_46_u * floorf(w);
	float t_4 = dX_46_w * floorf(d);
	float t_5 = dY_46_w * floorf(d);
	return log2f(sqrtf(fmaxf(((t_4 * t_4) + ((t_1 * t_1) + (t_3 * t_3))), ((t_5 * t_5) + ((t_0 * t_0) + (t_2 * t_2))))));
}
function code(w, h, d, dX_46_u, dX_46_v, dX_46_w, dY_46_u, dY_46_v, dY_46_w)
	t_0 = Float32(dY_46_v * floor(h))
	t_1 = Float32(dX_46_v * floor(h))
	t_2 = Float32(dY_46_u * floor(w))
	t_3 = Float32(dX_46_u * floor(w))
	t_4 = Float32(dX_46_w * floor(d))
	t_5 = Float32(dY_46_w * floor(d))
	return log2(sqrt(fmax(Float32(Float32(t_4 * t_4) + Float32(Float32(t_1 * t_1) + Float32(t_3 * t_3))), Float32(Float32(t_5 * t_5) + Float32(Float32(t_0 * t_0) + Float32(t_2 * t_2))))))
end
function tmp = code(w, h, d, dX_46_u, dX_46_v, dX_46_w, dY_46_u, dY_46_v, dY_46_w)
	t_0 = dY_46_v * floor(h);
	t_1 = dX_46_v * floor(h);
	t_2 = dY_46_u * floor(w);
	t_3 = dX_46_u * floor(w);
	t_4 = dX_46_w * floor(d);
	t_5 = dY_46_w * floor(d);
	tmp = log2(sqrt(max(((t_4 * t_4) + ((t_1 * t_1) + (t_3 * t_3))), ((t_5 * t_5) + ((t_0 * t_0) + (t_2 * t_2))))));
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := dY.v \cdot \left\lfloor h\right\rfloor \\
t_1 := dX.v \cdot \left\lfloor h\right\rfloor \\
t_2 := dY.u \cdot \left\lfloor w\right\rfloor \\
t_3 := dX.u \cdot \left\lfloor w\right\rfloor \\
t_4 := dX.w \cdot \left\lfloor d\right\rfloor \\
t_5 := dY.w \cdot \left\lfloor d\right\rfloor \\
\log_{2} \left(\sqrt{\mathsf{max}\left(t\_4 \cdot t\_4 + \left(t\_1 \cdot t\_1 + t\_3 \cdot t\_3\right), t\_5 \cdot t\_5 + \left(t\_0 \cdot t\_0 + t\_2 \cdot t\_2\right)\right)}\right)
\end{array}
\end{array}
Derivation
  1. Initial program 69.3%

    \[\log_{2} \left(\sqrt{\mathsf{max}\left(\left(\left(\left\lfloor w\right\rfloor \cdot dX.u\right) \cdot \left(\left\lfloor w\right\rfloor \cdot dX.u\right) + \left(\left\lfloor h\right\rfloor \cdot dX.v\right) \cdot \left(\left\lfloor h\right\rfloor \cdot dX.v\right)\right) + \left(\left\lfloor d\right\rfloor \cdot dX.w\right) \cdot \left(\left\lfloor d\right\rfloor \cdot dX.w\right), \left(\left(\left\lfloor w\right\rfloor \cdot dY.u\right) \cdot \left(\left\lfloor w\right\rfloor \cdot dY.u\right) + \left(\left\lfloor h\right\rfloor \cdot dY.v\right) \cdot \left(\left\lfloor h\right\rfloor \cdot dY.v\right)\right) + \left(\left\lfloor d\right\rfloor \cdot dY.w\right) \cdot \left(\left\lfloor d\right\rfloor \cdot dY.w\right)\right)}\right) \]
  2. Add Preprocessing
  3. Final simplification69.3%

    \[\leadsto \log_{2} \left(\sqrt{\mathsf{max}\left(\left(dX.w \cdot \left\lfloor d\right\rfloor \right) \cdot \left(dX.w \cdot \left\lfloor d\right\rfloor \right) + \left(\left(dX.v \cdot \left\lfloor h\right\rfloor \right) \cdot \left(dX.v \cdot \left\lfloor h\right\rfloor \right) + \left(dX.u \cdot \left\lfloor w\right\rfloor \right) \cdot \left(dX.u \cdot \left\lfloor w\right\rfloor \right)\right), \left(dY.w \cdot \left\lfloor d\right\rfloor \right) \cdot \left(dY.w \cdot \left\lfloor d\right\rfloor \right) + \left(\left(dY.v \cdot \left\lfloor h\right\rfloor \right) \cdot \left(dY.v \cdot \left\lfloor h\right\rfloor \right) + \left(dY.u \cdot \left\lfloor w\right\rfloor \right) \cdot \left(dY.u \cdot \left\lfloor w\right\rfloor \right)\right)\right)}\right) \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2024346 
(FPCore (w h d dX.u dX.v dX.w dY.u dY.v dY.w)
  :name "Isotropic LOD (LOD)"
  :precision binary32
  :pre (and (and (and (and (and (and (and (and (and (<= 1.0 w) (<= w 16384.0)) (and (<= 1.0 h) (<= h 16384.0))) (and (<= 1.0 d) (<= d 4096.0))) (and (<= 1e-20 (fabs dX.u)) (<= (fabs dX.u) 1e+20))) (and (<= 1e-20 (fabs dX.v)) (<= (fabs dX.v) 1e+20))) (and (<= 1e-20 (fabs dX.w)) (<= (fabs dX.w) 1e+20))) (and (<= 1e-20 (fabs dY.u)) (<= (fabs dY.u) 1e+20))) (and (<= 1e-20 (fabs dY.v)) (<= (fabs dY.v) 1e+20))) (and (<= 1e-20 (fabs dY.w)) (<= (fabs dY.w) 1e+20)))
  (log2 (sqrt (fmax (+ (+ (* (* (floor w) dX.u) (* (floor w) dX.u)) (* (* (floor h) dX.v) (* (floor h) dX.v))) (* (* (floor d) dX.w) (* (floor d) dX.w))) (+ (+ (* (* (floor w) dY.u) (* (floor w) dY.u)) (* (* (floor h) dY.v) (* (floor h) dY.v))) (* (* (floor d) dY.w) (* (floor d) dY.w)))))))