
(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 (if (<= y -6.8e-41) (* z y) (if (<= y 0.0065) x (if (<= y 7.2e+65) (* z y) (* x (- 0.0 y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e-41) {
tmp = z * y;
} else if (y <= 0.0065) {
tmp = x;
} else if (y <= 7.2e+65) {
tmp = z * y;
} else {
tmp = x * (0.0 - 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 <= (-6.8d-41)) then
tmp = z * y
else if (y <= 0.0065d0) then
tmp = x
else if (y <= 7.2d+65) then
tmp = z * y
else
tmp = x * (0.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -6.8e-41) {
tmp = z * y;
} else if (y <= 0.0065) {
tmp = x;
} else if (y <= 7.2e+65) {
tmp = z * y;
} else {
tmp = x * (0.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.8e-41: tmp = z * y elif y <= 0.0065: tmp = x elif y <= 7.2e+65: tmp = z * y else: tmp = x * (0.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.8e-41) tmp = Float64(z * y); elseif (y <= 0.0065) tmp = x; elseif (y <= 7.2e+65) tmp = Float64(z * y); else tmp = Float64(x * Float64(0.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.8e-41) tmp = z * y; elseif (y <= 0.0065) tmp = x; elseif (y <= 7.2e+65) tmp = z * y; else tmp = x * (0.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.8e-41], N[(z * y), $MachinePrecision], If[LessEqual[y, 0.0065], x, If[LessEqual[y, 7.2e+65], N[(z * y), $MachinePrecision], N[(x * N[(0.0 - y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{-41}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 0.0065:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{+65}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0 - y\right)\\
\end{array}
\end{array}
if y < -6.7999999999999997e-41 or 0.0064999999999999997 < y < 7.19999999999999957e65Initial program 99.9%
Taylor expanded in x around 0
*-lowering-*.f6455.8%
Simplified55.8%
if -6.7999999999999997e-41 < y < 0.0064999999999999997Initial program 100.0%
Taylor expanded in y around 0
Simplified73.0%
if 7.19999999999999957e65 < y Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f6470.0%
Simplified70.0%
flip--N/A
clear-numN/A
un-div-invN/A
/-lowering-/.f64N/A
clear-numN/A
flip--N/A
/-lowering-/.f64N/A
--lowering--.f6469.8%
Applied egg-rr69.8%
Taylor expanded in y around inf
/-lowering-/.f6469.8%
Simplified69.8%
frac-2negN/A
distribute-frac-negN/A
neg-lowering-neg.f64N/A
div-invN/A
distribute-neg-fracN/A
clear-numN/A
metadata-evalN/A
/-rgt-identityN/A
*-lowering-*.f6470.0%
Applied egg-rr70.0%
Final simplification67.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z x) y))) (if (<= y -1.0) t_0 (if (<= y 1.0) (+ 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 <= 1.0) {
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 <= 1.0d0) 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 <= 1.0) {
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 <= 1.0: 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 <= 1.0) 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 <= 1.0) 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, 1.0], 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 1:\\
\;\;\;\;x + z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
--lowering--.f6498.5%
Simplified98.5%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6498.2%
Simplified98.2%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- z x) y))) (if (<= y -0.00023) t_0 (if (<= y 0.25) (* x (- 1.0 y)) t_0))))
double code(double x, double y, double z) {
double t_0 = (z - x) * y;
double tmp;
if (y <= -0.00023) {
tmp = t_0;
} else if (y <= 0.25) {
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 <= (-0.00023d0)) then
tmp = t_0
else if (y <= 0.25d0) 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 <= -0.00023) {
tmp = t_0;
} else if (y <= 0.25) {
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 <= -0.00023: tmp = t_0 elif y <= 0.25: 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 <= -0.00023) tmp = t_0; elseif (y <= 0.25) 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 <= -0.00023) tmp = t_0; elseif (y <= 0.25) 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, -0.00023], t$95$0, If[LessEqual[y, 0.25], 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 -0.00023:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.25:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.3000000000000001e-4 or 0.25 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
--lowering--.f6498.5%
Simplified98.5%
if -2.3000000000000001e-4 < y < 0.25Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f6473.0%
Simplified73.0%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.22e+64) (* z y) (if (<= z 6.8e+167) (* x (- 1.0 y)) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.22e+64) {
tmp = z * y;
} else if (z <= 6.8e+167) {
tmp = x * (1.0 - y);
} 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 (z <= (-1.22d+64)) then
tmp = z * y
else if (z <= 6.8d+167) then
tmp = x * (1.0d0 - y)
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.22e+64) {
tmp = z * y;
} else if (z <= 6.8e+167) {
tmp = x * (1.0 - y);
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.22e+64: tmp = z * y elif z <= 6.8e+167: tmp = x * (1.0 - y) else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.22e+64) tmp = Float64(z * y); elseif (z <= 6.8e+167) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.22e+64) tmp = z * y; elseif (z <= 6.8e+167) tmp = x * (1.0 - y); else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.22e+64], N[(z * y), $MachinePrecision], If[LessEqual[z, 6.8e+167], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.22 \cdot 10^{+64}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 6.8 \cdot 10^{+167}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -1.21999999999999994e64 or 6.8000000000000001e167 < z Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6472.1%
Simplified72.1%
if -1.21999999999999994e64 < z < 6.8000000000000001e167Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
mul-1-negN/A
unsub-negN/A
--lowering--.f6480.7%
Simplified80.7%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (if (<= y -4e-41) (* z y) (if (<= y 0.006) x (* z y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e-41) {
tmp = z * y;
} else if (y <= 0.006) {
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 <= (-4d-41)) then
tmp = z * y
else if (y <= 0.006d0) 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 <= -4e-41) {
tmp = z * y;
} else if (y <= 0.006) {
tmp = x;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e-41: tmp = z * y elif y <= 0.006: tmp = x else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e-41) tmp = Float64(z * y); elseif (y <= 0.006) tmp = x; else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4e-41) tmp = z * y; elseif (y <= 0.006) tmp = x; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e-41], N[(z * y), $MachinePrecision], If[LessEqual[y, 0.006], x, N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-41}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 0.006:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -4.00000000000000002e-41 or 0.0060000000000000001 < y Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6448.2%
Simplified48.2%
if -4.00000000000000002e-41 < y < 0.0060000000000000001Initial program 100.0%
Taylor expanded in y around 0
Simplified73.0%
Final simplification59.9%
(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
Simplified37.3%
herbie shell --seed 2024145
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))