
(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 7 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%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -8.4e-54)
(* y z)
(if (<= y 1.4e-58)
(* 1.0 x)
(if (<= y 2.4e+61) (* y z) (if (<= y 2.6e+140) (* (- x) y) (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e-54) {
tmp = y * z;
} else if (y <= 1.4e-58) {
tmp = 1.0 * x;
} else if (y <= 2.4e+61) {
tmp = y * z;
} else if (y <= 2.6e+140) {
tmp = -x * y;
} else {
tmp = y * z;
}
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 <= (-8.4d-54)) then
tmp = y * z
else if (y <= 1.4d-58) then
tmp = 1.0d0 * x
else if (y <= 2.4d+61) then
tmp = y * z
else if (y <= 2.6d+140) then
tmp = -x * y
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e-54) {
tmp = y * z;
} else if (y <= 1.4e-58) {
tmp = 1.0 * x;
} else if (y <= 2.4e+61) {
tmp = y * z;
} else if (y <= 2.6e+140) {
tmp = -x * y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.4e-54: tmp = y * z elif y <= 1.4e-58: tmp = 1.0 * x elif y <= 2.4e+61: tmp = y * z elif y <= 2.6e+140: tmp = -x * y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.4e-54) tmp = Float64(y * z); elseif (y <= 1.4e-58) tmp = Float64(1.0 * x); elseif (y <= 2.4e+61) tmp = Float64(y * z); elseif (y <= 2.6e+140) tmp = Float64(Float64(-x) * y); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.4e-54) tmp = y * z; elseif (y <= 1.4e-58) tmp = 1.0 * x; elseif (y <= 2.4e+61) tmp = y * z; elseif (y <= 2.6e+140) tmp = -x * y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.4e-54], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.4e-58], N[(1.0 * x), $MachinePrecision], If[LessEqual[y, 2.4e+61], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.6e+140], N[((-x) * y), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.4 \cdot 10^{-54}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-58}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+61}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{+140}:\\
\;\;\;\;\left(-x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -8.4e-54 or 1.4e-58 < y < 2.3999999999999999e61 or 2.6000000000000001e140 < y Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6461.5
Applied rewrites61.5%
if -8.4e-54 < y < 1.4e-58Initial program 100.0%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6475.2
Applied rewrites75.2%
Taylor expanded in y around 0
Applied rewrites75.2%
if 2.3999999999999999e61 < y < 2.6000000000000001e140Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in z around 0
Applied rewrites74.8%
Final simplification68.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- z x)))) (if (<= y -8600.0) t_0 (if (<= y 9e-16) (+ (* y z) x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -8600.0) {
tmp = t_0;
} else if (y <= 9e-16) {
tmp = (y * z) + x;
} 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 = y * (z - x)
if (y <= (-8600.0d0)) then
tmp = t_0
else if (y <= 9d-16) then
tmp = (y * z) + x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -8600.0) {
tmp = t_0;
} else if (y <= 9e-16) {
tmp = (y * z) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z - x) tmp = 0 if y <= -8600.0: tmp = t_0 elif y <= 9e-16: tmp = (y * z) + x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (y <= -8600.0) tmp = t_0; elseif (y <= 9e-16) tmp = Float64(Float64(y * z) + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (z - x); tmp = 0.0; if (y <= -8600.0) tmp = t_0; elseif (y <= 9e-16) tmp = (y * z) + x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8600.0], t$95$0, If[LessEqual[y, 9e-16], N[(N[(y * z), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -8600:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 9 \cdot 10^{-16}:\\
\;\;\;\;y \cdot z + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8600 or 9.0000000000000003e-16 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6499.4
Applied rewrites99.4%
if -8600 < y < 9.0000000000000003e-16Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6499.3
Applied rewrites99.3%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- z x)))) (if (<= y -8e-54) t_0 (if (<= y 9.8e-43) (* 1.0 x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -8e-54) {
tmp = t_0;
} else if (y <= 9.8e-43) {
tmp = 1.0 * x;
} 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 = y * (z - x)
if (y <= (-8d-54)) then
tmp = t_0
else if (y <= 9.8d-43) then
tmp = 1.0d0 * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -8e-54) {
tmp = t_0;
} else if (y <= 9.8e-43) {
tmp = 1.0 * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z - x) tmp = 0 if y <= -8e-54: tmp = t_0 elif y <= 9.8e-43: tmp = 1.0 * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (y <= -8e-54) tmp = t_0; elseif (y <= 9.8e-43) tmp = Float64(1.0 * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (z - x); tmp = 0.0; if (y <= -8e-54) tmp = t_0; elseif (y <= 9.8e-43) tmp = 1.0 * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8e-54], t$95$0, If[LessEqual[y, 9.8e-43], N[(1.0 * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -8 \cdot 10^{-54}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 9.8 \cdot 10^{-43}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.0000000000000002e-54 or 9.79999999999999976e-43 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6495.7
Applied rewrites95.7%
if -8.0000000000000002e-54 < y < 9.79999999999999976e-43Initial program 100.0%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6474.7
Applied rewrites74.7%
Taylor expanded in y around 0
Applied rewrites74.7%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (<= z -5.8e+43) (* y z) (if (<= z 5.2e+29) (* (- 1.0 y) x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.8e+43) {
tmp = y * z;
} else if (z <= 5.2e+29) {
tmp = (1.0 - y) * x;
} else {
tmp = y * z;
}
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 <= (-5.8d+43)) then
tmp = y * z
else if (z <= 5.2d+29) then
tmp = (1.0d0 - y) * x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -5.8e+43) {
tmp = y * z;
} else if (z <= 5.2e+29) {
tmp = (1.0 - y) * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.8e+43: tmp = y * z elif z <= 5.2e+29: tmp = (1.0 - y) * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.8e+43) tmp = Float64(y * z); elseif (z <= 5.2e+29) tmp = Float64(Float64(1.0 - y) * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.8e+43) tmp = y * z; elseif (z <= 5.2e+29) tmp = (1.0 - y) * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.8e+43], N[(y * z), $MachinePrecision], If[LessEqual[z, 5.2e+29], N[(N[(1.0 - y), $MachinePrecision] * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{+43}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5.2 \cdot 10^{+29}:\\
\;\;\;\;\left(1 - y\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -5.8000000000000004e43 or 5.2e29 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6474.8
Applied rewrites74.8%
if -5.8000000000000004e43 < z < 5.2e29Initial program 100.0%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6482.0
Applied rewrites82.0%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (<= y -8.4e-54) (* y z) (if (<= y 1.4e-58) (* 1.0 x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e-54) {
tmp = y * z;
} else if (y <= 1.4e-58) {
tmp = 1.0 * x;
} else {
tmp = y * z;
}
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 <= (-8.4d-54)) then
tmp = y * z
else if (y <= 1.4d-58) then
tmp = 1.0d0 * x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8.4e-54) {
tmp = y * z;
} else if (y <= 1.4e-58) {
tmp = 1.0 * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.4e-54: tmp = y * z elif y <= 1.4e-58: tmp = 1.0 * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.4e-54) tmp = Float64(y * z); elseif (y <= 1.4e-58) tmp = Float64(1.0 * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.4e-54) tmp = y * z; elseif (y <= 1.4e-58) tmp = 1.0 * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.4e-54], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.4e-58], N[(1.0 * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.4 \cdot 10^{-54}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-58}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -8.4e-54 or 1.4e-58 < y Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6457.3
Applied rewrites57.3%
if -8.4e-54 < y < 1.4e-58Initial program 100.0%
Taylor expanded in z around 0
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
distribute-rgt1-inN/A
+-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f6475.2
Applied rewrites75.2%
Taylor expanded in y around 0
Applied rewrites75.2%
Final simplification64.6%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return y * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6445.0
Applied rewrites45.0%
Final simplification45.0%
herbie shell --seed 2024264
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))