
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (- z x) y x))
double code(double x, double y, double z) {
return fma((z - x), y, x);
}
function code(x, y, z) return fma(Float64(z - x), y, x) end
code[x_, y_, z_] := N[(N[(z - x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z - x, y, x\right)
\end{array}
Initial program 100.0%
+-commutativeN/A
*-commutativeN/A
fma-defineN/A
fma-lowering-fma.f64N/A
--lowering--.f64100.0%
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z x) y))) (if (<= y -1.0) t_0 (if (<= y 5.2e-12) (+ x (* z y)) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 5.2e-12) {
tmp = x + (z * y);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (z - x) * y
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 5.2d-12) then
tmp = x + (z * y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 5.2e-12) {
tmp = x + (z * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z - x) * y tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 5.2e-12: tmp = x + (z * y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z - x) * y) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 5.2e-12) tmp = Float64(x + Float64(z * y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z - x) * y; tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 5.2e-12) tmp = x + (z * y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 5.2e-12], N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - x\right) \cdot y\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-12}:\\
\;\;\;\;x + z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 5.19999999999999965e-12 < y Initial program 99.9%
Taylor expanded in y around inf
*-lowering-*.f64N/A
--lowering--.f6496.8%
Simplified96.8%
if -1 < y < 5.19999999999999965e-12Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6498.9%
Simplified98.9%
Final simplification97.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z x) y))) (if (<= y -38000000.0) t_0 (if (<= y 1.6e-82) (* x (- 1.0 y)) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -38000000.0) {
tmp = t_0;
} else if (y <= 1.6e-82) {
tmp = x * (1.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (z - x) * y
if (y <= (-38000000.0d0)) then
tmp = t_0
else if (y <= 1.6d-82) then
tmp = x * (1.0d0 - y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -38000000.0) {
tmp = t_0;
} else if (y <= 1.6e-82) {
tmp = x * (1.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z - x) * y tmp = 0 if y <= -38000000.0: tmp = t_0 elif y <= 1.6e-82: tmp = x * (1.0 - y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z - x) * y) tmp = 0.0 if (y <= -38000000.0) tmp = t_0; elseif (y <= 1.6e-82) tmp = Float64(x * Float64(1.0 - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z - x) * y; tmp = 0.0; if (y <= -38000000.0) tmp = t_0; elseif (y <= 1.6e-82) tmp = x * (1.0 - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -38000000.0], t$95$0, If[LessEqual[y, 1.6e-82], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z - x\right) \cdot y\\
\mathbf{if}\;y \leq -38000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{-82}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.8e7 or 1.6000000000000001e-82 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
--lowering--.f6492.4%
Simplified92.4%
if -3.8e7 < y < 1.6000000000000001e-82Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f6483.2%
Simplified83.2%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- 1.0 y)))) (if (<= x -8.5e-30) t_0 (if (<= x 9.2e-241) (* z y) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -8.5e-30) {
tmp = t_0;
} else if (x <= 9.2e-241) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x * (1.0d0 - y)
if (x <= (-8.5d-30)) then
tmp = t_0
else if (x <= 9.2d-241) then
tmp = z * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - y);
double tmp;
if (x <= -8.5e-30) {
tmp = t_0;
} else if (x <= 9.2e-241) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (1.0 - y) tmp = 0 if x <= -8.5e-30: tmp = t_0 elif x <= 9.2e-241: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(1.0 - y)) tmp = 0.0 if (x <= -8.5e-30) tmp = t_0; elseif (x <= 9.2e-241) tmp = Float64(z * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (1.0 - y); tmp = 0.0; if (x <= -8.5e-30) tmp = t_0; elseif (x <= 9.2e-241) tmp = z * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8.5e-30], t$95$0, If[LessEqual[x, 9.2e-241], N[(z * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - y\right)\\
\mathbf{if}\;x \leq -8.5 \cdot 10^{-30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 9.2 \cdot 10^{-241}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -8.49999999999999931e-30 or 9.1999999999999997e-241 < x Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f6480.8%
Simplified80.8%
if -8.49999999999999931e-30 < x < 9.1999999999999997e-241Initial program 99.9%
Taylor expanded in x around 0
*-lowering-*.f6470.5%
Simplified70.5%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (+ x (* y (* (+ z x) (/ (- z x) (+ z x))))))
double code(double x, double y, double z) {
return x + (y * ((z + x) * ((z - x) / (z + x))));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * ((z + x) * ((z - x) / (z + x))))
end function
public static double code(double x, double y, double z) {
return x + (y * ((z + x) * ((z - x) / (z + x))));
}
def code(x, y, z): return x + (y * ((z + x) * ((z - x) / (z + x))))
function code(x, y, z) return Float64(x + Float64(y * Float64(Float64(z + x) * Float64(Float64(z - x) / Float64(z + x))))) end
function tmp = code(x, y, z) tmp = x + (y * ((z + x) * ((z - x) / (z + x)))); end
code[x_, y_, z_] := N[(x + N[(y * N[(N[(z + x), $MachinePrecision] * N[(N[(z - x), $MachinePrecision] / N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(\left(z + x\right) \cdot \frac{z - x}{z + x}\right)
\end{array}
Initial program 100.0%
flip--N/A
difference-of-squaresN/A
associate-/l*N/A
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
--lowering--.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -3.2e-23) (* z y) (if (<= y 1.6e-82) x (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e-23) {
tmp = z * y;
} else if (y <= 1.6e-82) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-3.2d-23)) then
tmp = z * y
else if (y <= 1.6d-82) then
tmp = x
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e-23) {
tmp = z * y;
} else if (y <= 1.6e-82) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.2e-23: tmp = z * y elif y <= 1.6e-82: tmp = x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.2e-23) tmp = Float64(z * y); elseif (y <= 1.6e-82) tmp = x; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.2e-23) tmp = z * y; elseif (y <= 1.6e-82) tmp = x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.2e-23], N[(z * y), $MachinePrecision], If[LessEqual[y, 1.6e-82], x, N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{-23}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{-82}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -3.19999999999999976e-23 or 1.6000000000000001e-82 < y Initial program 99.9%
Taylor expanded in x around 0
*-lowering-*.f6450.8%
Simplified50.8%
if -3.19999999999999976e-23 < y < 1.6000000000000001e-82Initial program 100.0%
Taylor expanded in y around 0
Simplified85.1%
Final simplification64.5%
(FPCore (x y z) :precision binary64 (+ x (* (- z x) y)))
double code(double x, double y, double z) {
return x + ((z - x) * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + ((z - x) * y)
end function
public static double code(double x, double y, double z) {
return x + ((z - x) * y);
}
def code(x, y, z): return x + ((z - x) * y)
function code(x, y, z) return Float64(x + Float64(Float64(z - x) * y)) end
function tmp = code(x, y, z) tmp = x + ((z - x) * y); end
code[x_, y_, z_] := N[(x + N[(N[(z - x), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(z - x\right) \cdot y
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
Simplified39.4%
herbie shell --seed 2024140
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))