
(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 y (- z x) x))
double code(double x, double y, double z) {
return fma(y, (z - x), x);
}
function code(x, y, z) return fma(y, Float64(z - x), x) end
code[x_, y_, z_] := N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, z - x, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -5.2e+113)
t_0
(if (<= y -2.9e+63)
(* y z)
(if (<= y -17000000000000.0)
t_0
(if (<= y -2.5e-75) (* y z) (if (<= y 520000000000.0) x t_0)))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -5.2e+113) {
tmp = t_0;
} else if (y <= -2.9e+63) {
tmp = y * z;
} else if (y <= -17000000000000.0) {
tmp = t_0;
} else if (y <= -2.5e-75) {
tmp = y * z;
} else if (y <= 520000000000.0) {
tmp = 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 * -x
if (y <= (-5.2d+113)) then
tmp = t_0
else if (y <= (-2.9d+63)) then
tmp = y * z
else if (y <= (-17000000000000.0d0)) then
tmp = t_0
else if (y <= (-2.5d-75)) then
tmp = y * z
else if (y <= 520000000000.0d0) then
tmp = 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 * -x;
double tmp;
if (y <= -5.2e+113) {
tmp = t_0;
} else if (y <= -2.9e+63) {
tmp = y * z;
} else if (y <= -17000000000000.0) {
tmp = t_0;
} else if (y <= -2.5e-75) {
tmp = y * z;
} else if (y <= 520000000000.0) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -5.2e+113: tmp = t_0 elif y <= -2.9e+63: tmp = y * z elif y <= -17000000000000.0: tmp = t_0 elif y <= -2.5e-75: tmp = y * z elif y <= 520000000000.0: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -5.2e+113) tmp = t_0; elseif (y <= -2.9e+63) tmp = Float64(y * z); elseif (y <= -17000000000000.0) tmp = t_0; elseif (y <= -2.5e-75) tmp = Float64(y * z); elseif (y <= 520000000000.0) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -5.2e+113) tmp = t_0; elseif (y <= -2.9e+63) tmp = y * z; elseif (y <= -17000000000000.0) tmp = t_0; elseif (y <= -2.5e-75) tmp = y * z; elseif (y <= 520000000000.0) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -5.2e+113], t$95$0, If[LessEqual[y, -2.9e+63], N[(y * z), $MachinePrecision], If[LessEqual[y, -17000000000000.0], t$95$0, If[LessEqual[y, -2.5e-75], N[(y * z), $MachinePrecision], If[LessEqual[y, 520000000000.0], x, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -5.2 \cdot 10^{+113}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.9 \cdot 10^{+63}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -17000000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.5 \cdot 10^{-75}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 520000000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -5.1999999999999998e113 or -2.8999999999999999e63 < y < -1.7e13 or 5.2e11 < y Initial program 100.0%
Taylor expanded in x around inf 67.3%
+-commutative67.3%
distribute-rgt1-in67.2%
mul-1-neg67.2%
cancel-sign-sub-inv67.2%
Simplified67.2%
Taylor expanded in y around inf 67.0%
associate-*r*67.0%
mul-1-neg67.0%
Simplified67.0%
if -5.1999999999999998e113 < y < -2.8999999999999999e63 or -1.7e13 < y < -2.49999999999999989e-75Initial program 99.9%
Taylor expanded in x around 0 65.2%
if -2.49999999999999989e-75 < y < 5.2e11Initial program 100.0%
Taylor expanded in y around 0 74.3%
Final simplification70.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.36e-71) (not (<= y 1.7e-5))) (* y (- z x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.36e-71) || !(y <= 1.7e-5)) {
tmp = y * (z - x);
} else {
tmp = x;
}
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 <= (-1.36d-71)) .or. (.not. (y <= 1.7d-5))) then
tmp = y * (z - x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.36e-71) || !(y <= 1.7e-5)) {
tmp = y * (z - x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.36e-71) or not (y <= 1.7e-5): tmp = y * (z - x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.36e-71) || !(y <= 1.7e-5)) tmp = Float64(y * Float64(z - x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.36e-71) || ~((y <= 1.7e-5))) tmp = y * (z - x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.36e-71], N[Not[LessEqual[y, 1.7e-5]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.36 \cdot 10^{-71} \lor \neg \left(y \leq 1.7 \cdot 10^{-5}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.3599999999999999e-71 or 1.7e-5 < y Initial program 100.0%
Taylor expanded in y around inf 94.2%
if -1.3599999999999999e-71 < y < 1.7e-5Initial program 100.0%
Taylor expanded in y around 0 75.4%
Final simplification85.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.36e-71) (not (<= y 0.00018))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.36e-71) || !(y <= 0.00018)) {
tmp = y * (z - x);
} else {
tmp = x * (1.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 <= (-1.36d-71)) .or. (.not. (y <= 0.00018d0))) then
tmp = y * (z - x)
else
tmp = x * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.36e-71) || !(y <= 0.00018)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.36e-71) or not (y <= 0.00018): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.36e-71) || !(y <= 0.00018)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.36e-71) || ~((y <= 0.00018))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.36e-71], N[Not[LessEqual[y, 0.00018]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.36 \cdot 10^{-71} \lor \neg \left(y \leq 0.00018\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -1.3599999999999999e-71 or 1.80000000000000011e-4 < y Initial program 100.0%
Taylor expanded in y around inf 94.2%
if -1.3599999999999999e-71 < y < 1.80000000000000011e-4Initial program 100.0%
Taylor expanded in x around inf 76.9%
+-commutative76.9%
distribute-rgt1-in77.0%
mul-1-neg77.0%
cancel-sign-sub-inv77.0%
Simplified77.0%
Taylor expanded in x around 0 76.9%
Final simplification85.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.0034))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.0034)) {
tmp = y * (z - x);
} else {
tmp = x + (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 <= (-1.0d0)) .or. (.not. (y <= 0.0034d0))) then
tmp = y * (z - x)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.0034)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 0.0034): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.0034)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 0.0034))) tmp = y * (z - x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 0.0034]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.0034\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1 or 0.00339999999999999981 < y Initial program 100.0%
Taylor expanded in y around inf 99.2%
if -1 < y < 0.00339999999999999981Initial program 100.0%
flip--59.9%
associate-*r/59.9%
+-commutative59.9%
Applied egg-rr59.9%
*-commutative59.9%
associate-/l*57.8%
+-commutative57.8%
Simplified57.8%
Taylor expanded in z around inf 98.2%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= y -1.36e-71) (* y z) (if (<= y 3.1e-5) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.36e-71) {
tmp = y * z;
} else if (y <= 3.1e-5) {
tmp = 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 <= (-1.36d-71)) then
tmp = y * z
else if (y <= 3.1d-5) then
tmp = 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 <= -1.36e-71) {
tmp = y * z;
} else if (y <= 3.1e-5) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.36e-71: tmp = y * z elif y <= 3.1e-5: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.36e-71) tmp = Float64(y * z); elseif (y <= 3.1e-5) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.36e-71) tmp = y * z; elseif (y <= 3.1e-5) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.36e-71], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.1e-5], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.36 \cdot 10^{-71}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.3599999999999999e-71 or 3.10000000000000014e-5 < y Initial program 100.0%
Taylor expanded in x around 0 46.5%
if -1.3599999999999999e-71 < y < 3.10000000000000014e-5Initial program 100.0%
Taylor expanded in y around 0 75.4%
Final simplification60.4%
(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}
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 40.3%
Final simplification40.3%
herbie shell --seed 2023238
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))