
(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 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 (* x (- y))))
(if (<= y -3.9e+253)
t_0
(if (<= y -8.5e+111)
(* y z)
(if (<= y -1.0)
t_0
(if (<= y 3.3e-24)
x
(if (or (<= y 9e+22)
(and (not (<= y 3.5e+177))
(or (<= y 1.1e+186)
(and (not (<= y 4.1e+207)) (<= y 5.4e+223)))))
(* y z)
t_0)))))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -3.9e+253) {
tmp = t_0;
} else if (y <= -8.5e+111) {
tmp = y * z;
} else if (y <= -1.0) {
tmp = t_0;
} else if (y <= 3.3e-24) {
tmp = x;
} else if ((y <= 9e+22) || (!(y <= 3.5e+177) && ((y <= 1.1e+186) || (!(y <= 4.1e+207) && (y <= 5.4e+223))))) {
tmp = y * z;
} 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 * -y
if (y <= (-3.9d+253)) then
tmp = t_0
else if (y <= (-8.5d+111)) then
tmp = y * z
else if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 3.3d-24) then
tmp = x
else if ((y <= 9d+22) .or. (.not. (y <= 3.5d+177)) .and. (y <= 1.1d+186) .or. (.not. (y <= 4.1d+207)) .and. (y <= 5.4d+223)) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (y <= -3.9e+253) {
tmp = t_0;
} else if (y <= -8.5e+111) {
tmp = y * z;
} else if (y <= -1.0) {
tmp = t_0;
} else if (y <= 3.3e-24) {
tmp = x;
} else if ((y <= 9e+22) || (!(y <= 3.5e+177) && ((y <= 1.1e+186) || (!(y <= 4.1e+207) && (y <= 5.4e+223))))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if y <= -3.9e+253: tmp = t_0 elif y <= -8.5e+111: tmp = y * z elif y <= -1.0: tmp = t_0 elif y <= 3.3e-24: tmp = x elif (y <= 9e+22) or (not (y <= 3.5e+177) and ((y <= 1.1e+186) or (not (y <= 4.1e+207) and (y <= 5.4e+223)))): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (y <= -3.9e+253) tmp = t_0; elseif (y <= -8.5e+111) tmp = Float64(y * z); elseif (y <= -1.0) tmp = t_0; elseif (y <= 3.3e-24) tmp = x; elseif ((y <= 9e+22) || (!(y <= 3.5e+177) && ((y <= 1.1e+186) || (!(y <= 4.1e+207) && (y <= 5.4e+223))))) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (y <= -3.9e+253) tmp = t_0; elseif (y <= -8.5e+111) tmp = y * z; elseif (y <= -1.0) tmp = t_0; elseif (y <= 3.3e-24) tmp = x; elseif ((y <= 9e+22) || (~((y <= 3.5e+177)) && ((y <= 1.1e+186) || (~((y <= 4.1e+207)) && (y <= 5.4e+223))))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[y, -3.9e+253], t$95$0, If[LessEqual[y, -8.5e+111], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 3.3e-24], x, If[Or[LessEqual[y, 9e+22], And[N[Not[LessEqual[y, 3.5e+177]], $MachinePrecision], Or[LessEqual[y, 1.1e+186], And[N[Not[LessEqual[y, 4.1e+207]], $MachinePrecision], LessEqual[y, 5.4e+223]]]]], N[(y * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;y \leq -3.9 \cdot 10^{+253}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -8.5 \cdot 10^{+111}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-24}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 9 \cdot 10^{+22} \lor \neg \left(y \leq 3.5 \cdot 10^{+177}\right) \land \left(y \leq 1.1 \cdot 10^{+186} \lor \neg \left(y \leq 4.1 \cdot 10^{+207}\right) \land y \leq 5.4 \cdot 10^{+223}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -3.9000000000000001e253 or -8.49999999999999983e111 < y < -1 or 8.9999999999999996e22 < y < 3.49999999999999991e177 or 1.0999999999999999e186 < y < 4.1e207 or 5.4000000000000001e223 < y Initial program 100.0%
Taylor expanded in x around inf 73.1%
+-commutative73.1%
distribute-rgt1-in73.1%
mul-1-neg73.1%
cancel-sign-sub-inv73.1%
Simplified73.1%
Taylor expanded in y around inf 71.9%
mul-1-neg71.9%
distribute-rgt-neg-in71.9%
Simplified71.9%
if -3.9000000000000001e253 < y < -8.49999999999999983e111 or 3.29999999999999984e-24 < y < 8.9999999999999996e22 or 3.49999999999999991e177 < y < 1.0999999999999999e186 or 4.1e207 < y < 5.4000000000000001e223Initial program 100.0%
Taylor expanded in z around inf 73.9%
Taylor expanded in x around 0 69.6%
if -1 < y < 3.29999999999999984e-24Initial program 100.0%
Taylor expanded in y around 0 75.1%
Final simplification72.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y))) (t_1 (+ x (* y z))))
(if (<= y -4.3e+254)
t_0
(if (<= y -2.8e+112)
t_1
(if (<= y -1.35e+38)
t_0
(if (<= y 6.4e+29)
t_1
(if (or (<= y 2.9e+173)
(and (not (<= y 1.1e+186))
(or (<= y 2.05e+207) (not (<= y 4e+223)))))
t_0
(* y z))))))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double t_1 = x + (y * z);
double tmp;
if (y <= -4.3e+254) {
tmp = t_0;
} else if (y <= -2.8e+112) {
tmp = t_1;
} else if (y <= -1.35e+38) {
tmp = t_0;
} else if (y <= 6.4e+29) {
tmp = t_1;
} else if ((y <= 2.9e+173) || (!(y <= 1.1e+186) && ((y <= 2.05e+207) || !(y <= 4e+223)))) {
tmp = t_0;
} 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x * -y
t_1 = x + (y * z)
if (y <= (-4.3d+254)) then
tmp = t_0
else if (y <= (-2.8d+112)) then
tmp = t_1
else if (y <= (-1.35d+38)) then
tmp = t_0
else if (y <= 6.4d+29) then
tmp = t_1
else if ((y <= 2.9d+173) .or. (.not. (y <= 1.1d+186)) .and. (y <= 2.05d+207) .or. (.not. (y <= 4d+223))) then
tmp = t_0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -y;
double t_1 = x + (y * z);
double tmp;
if (y <= -4.3e+254) {
tmp = t_0;
} else if (y <= -2.8e+112) {
tmp = t_1;
} else if (y <= -1.35e+38) {
tmp = t_0;
} else if (y <= 6.4e+29) {
tmp = t_1;
} else if ((y <= 2.9e+173) || (!(y <= 1.1e+186) && ((y <= 2.05e+207) || !(y <= 4e+223)))) {
tmp = t_0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y t_1 = x + (y * z) tmp = 0 if y <= -4.3e+254: tmp = t_0 elif y <= -2.8e+112: tmp = t_1 elif y <= -1.35e+38: tmp = t_0 elif y <= 6.4e+29: tmp = t_1 elif (y <= 2.9e+173) or (not (y <= 1.1e+186) and ((y <= 2.05e+207) or not (y <= 4e+223))): tmp = t_0 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) t_1 = Float64(x + Float64(y * z)) tmp = 0.0 if (y <= -4.3e+254) tmp = t_0; elseif (y <= -2.8e+112) tmp = t_1; elseif (y <= -1.35e+38) tmp = t_0; elseif (y <= 6.4e+29) tmp = t_1; elseif ((y <= 2.9e+173) || (!(y <= 1.1e+186) && ((y <= 2.05e+207) || !(y <= 4e+223)))) tmp = t_0; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; t_1 = x + (y * z); tmp = 0.0; if (y <= -4.3e+254) tmp = t_0; elseif (y <= -2.8e+112) tmp = t_1; elseif (y <= -1.35e+38) tmp = t_0; elseif (y <= 6.4e+29) tmp = t_1; elseif ((y <= 2.9e+173) || (~((y <= 1.1e+186)) && ((y <= 2.05e+207) || ~((y <= 4e+223))))) tmp = t_0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.3e+254], t$95$0, If[LessEqual[y, -2.8e+112], t$95$1, If[LessEqual[y, -1.35e+38], t$95$0, If[LessEqual[y, 6.4e+29], t$95$1, If[Or[LessEqual[y, 2.9e+173], And[N[Not[LessEqual[y, 1.1e+186]], $MachinePrecision], Or[LessEqual[y, 2.05e+207], N[Not[LessEqual[y, 4e+223]], $MachinePrecision]]]], t$95$0, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
t_1 := x + y \cdot z\\
\mathbf{if}\;y \leq -4.3 \cdot 10^{+254}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.8 \cdot 10^{+112}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -1.35 \cdot 10^{+38}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{+29}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{+173} \lor \neg \left(y \leq 1.1 \cdot 10^{+186}\right) \land \left(y \leq 2.05 \cdot 10^{+207} \lor \neg \left(y \leq 4 \cdot 10^{+223}\right)\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -4.30000000000000012e254 or -2.8000000000000001e112 < y < -1.34999999999999998e38 or 6.39999999999999973e29 < y < 2.90000000000000007e173 or 1.0999999999999999e186 < y < 2.05e207 or 4.00000000000000019e223 < y Initial program 100.0%
Taylor expanded in x around inf 75.1%
+-commutative75.1%
distribute-rgt1-in75.1%
mul-1-neg75.1%
cancel-sign-sub-inv75.1%
Simplified75.1%
Taylor expanded in y around inf 75.1%
mul-1-neg75.1%
distribute-rgt-neg-in75.1%
Simplified75.1%
if -4.30000000000000012e254 < y < -2.8000000000000001e112 or -1.34999999999999998e38 < y < 6.39999999999999973e29Initial program 100.0%
Taylor expanded in z around inf 89.9%
if 2.90000000000000007e173 < y < 1.0999999999999999e186 or 2.05e207 < y < 4.00000000000000019e223Initial program 100.0%
Taylor expanded in z around inf 99.4%
Taylor expanded in x around 0 99.4%
Final simplification85.4%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.15e-49)
(not (or (<= x 7e-118) (and (not (<= x 6.2e-30)) (<= x 2.6e+55)))))
(- x (* y x))
(+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.15e-49) || !((x <= 7e-118) || (!(x <= 6.2e-30) && (x <= 2.6e+55)))) {
tmp = x - (y * 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 ((x <= (-1.15d-49)) .or. (.not. (x <= 7d-118) .or. (.not. (x <= 6.2d-30)) .and. (x <= 2.6d+55))) then
tmp = x - (y * 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 ((x <= -1.15e-49) || !((x <= 7e-118) || (!(x <= 6.2e-30) && (x <= 2.6e+55)))) {
tmp = x - (y * x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.15e-49) or not ((x <= 7e-118) or (not (x <= 6.2e-30) and (x <= 2.6e+55))): tmp = x - (y * x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.15e-49) || !((x <= 7e-118) || (!(x <= 6.2e-30) && (x <= 2.6e+55)))) tmp = Float64(x - Float64(y * x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.15e-49) || ~(((x <= 7e-118) || (~((x <= 6.2e-30)) && (x <= 2.6e+55))))) tmp = x - (y * x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.15e-49], N[Not[Or[LessEqual[x, 7e-118], And[N[Not[LessEqual[x, 6.2e-30]], $MachinePrecision], LessEqual[x, 2.6e+55]]]], $MachinePrecision]], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-49} \lor \neg \left(x \leq 7 \cdot 10^{-118} \lor \neg \left(x \leq 6.2 \cdot 10^{-30}\right) \land x \leq 2.6 \cdot 10^{+55}\right):\\
\;\;\;\;x - y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.15e-49 or 7e-118 < x < 6.19999999999999982e-30 or 2.6e55 < x Initial program 100.0%
Taylor expanded in x around inf 90.5%
+-commutative90.5%
distribute-rgt1-in90.5%
mul-1-neg90.5%
cancel-sign-sub-inv90.5%
Simplified90.5%
if -1.15e-49 < x < 7e-118 or 6.19999999999999982e-30 < x < 2.6e55Initial program 100.0%
Taylor expanded in z around inf 91.8%
Final simplification91.0%
(FPCore (x y z) :precision binary64 (if (<= y -5e-18) (* y z) (if (<= y 2.6e-24) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5e-18) {
tmp = y * z;
} else if (y <= 2.6e-24) {
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 <= (-5d-18)) then
tmp = y * z
else if (y <= 2.6d-24) 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 <= -5e-18) {
tmp = y * z;
} else if (y <= 2.6e-24) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5e-18: tmp = y * z elif y <= 2.6e-24: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5e-18) tmp = Float64(y * z); elseif (y <= 2.6e-24) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5e-18) tmp = y * z; elseif (y <= 2.6e-24) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5e-18], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.6e-24], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{-18}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-24}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -5.00000000000000036e-18 or 2.6e-24 < y Initial program 100.0%
Taylor expanded in z around inf 48.6%
Taylor expanded in x around 0 46.4%
if -5.00000000000000036e-18 < y < 2.6e-24Initial program 100.0%
Taylor expanded in y around 0 76.4%
Final simplification59.6%
(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 36.4%
Final simplification36.4%
herbie shell --seed 2023230
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))