
(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 6 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 (+ 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
(let* ((t_0 (* y (- x))))
(if (<= y -2.7e+229)
t_0
(if (<= y -1.7e+207)
(* y z)
(if (<= y -1.15e+133)
t_0
(if (<= y -1.6e+57)
(* y z)
(if (<= y -1.15e+27)
t_0
(if (<= y -2.8e-49)
(* y z)
(if (<= y 7.8e-84)
x
(if (<= y 3.9e-41)
(* y z)
(if (<= y 2.45e-14) x (* y z))))))))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -2.7e+229) {
tmp = t_0;
} else if (y <= -1.7e+207) {
tmp = y * z;
} else if (y <= -1.15e+133) {
tmp = t_0;
} else if (y <= -1.6e+57) {
tmp = y * z;
} else if (y <= -1.15e+27) {
tmp = t_0;
} else if (y <= -2.8e-49) {
tmp = y * z;
} else if (y <= 7.8e-84) {
tmp = x;
} else if (y <= 3.9e-41) {
tmp = y * z;
} else if (y <= 2.45e-14) {
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) :: t_0
real(8) :: tmp
t_0 = y * -x
if (y <= (-2.7d+229)) then
tmp = t_0
else if (y <= (-1.7d+207)) then
tmp = y * z
else if (y <= (-1.15d+133)) then
tmp = t_0
else if (y <= (-1.6d+57)) then
tmp = y * z
else if (y <= (-1.15d+27)) then
tmp = t_0
else if (y <= (-2.8d-49)) then
tmp = y * z
else if (y <= 7.8d-84) then
tmp = x
else if (y <= 3.9d-41) then
tmp = y * z
else if (y <= 2.45d-14) then
tmp = x
else
tmp = y * z
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 <= -2.7e+229) {
tmp = t_0;
} else if (y <= -1.7e+207) {
tmp = y * z;
} else if (y <= -1.15e+133) {
tmp = t_0;
} else if (y <= -1.6e+57) {
tmp = y * z;
} else if (y <= -1.15e+27) {
tmp = t_0;
} else if (y <= -2.8e-49) {
tmp = y * z;
} else if (y <= 7.8e-84) {
tmp = x;
} else if (y <= 3.9e-41) {
tmp = y * z;
} else if (y <= 2.45e-14) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -2.7e+229: tmp = t_0 elif y <= -1.7e+207: tmp = y * z elif y <= -1.15e+133: tmp = t_0 elif y <= -1.6e+57: tmp = y * z elif y <= -1.15e+27: tmp = t_0 elif y <= -2.8e-49: tmp = y * z elif y <= 7.8e-84: tmp = x elif y <= 3.9e-41: tmp = y * z elif y <= 2.45e-14: tmp = x else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -2.7e+229) tmp = t_0; elseif (y <= -1.7e+207) tmp = Float64(y * z); elseif (y <= -1.15e+133) tmp = t_0; elseif (y <= -1.6e+57) tmp = Float64(y * z); elseif (y <= -1.15e+27) tmp = t_0; elseif (y <= -2.8e-49) tmp = Float64(y * z); elseif (y <= 7.8e-84) tmp = x; elseif (y <= 3.9e-41) tmp = Float64(y * z); elseif (y <= 2.45e-14) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -2.7e+229) tmp = t_0; elseif (y <= -1.7e+207) tmp = y * z; elseif (y <= -1.15e+133) tmp = t_0; elseif (y <= -1.6e+57) tmp = y * z; elseif (y <= -1.15e+27) tmp = t_0; elseif (y <= -2.8e-49) tmp = y * z; elseif (y <= 7.8e-84) tmp = x; elseif (y <= 3.9e-41) tmp = y * z; elseif (y <= 2.45e-14) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -2.7e+229], t$95$0, If[LessEqual[y, -1.7e+207], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.15e+133], t$95$0, If[LessEqual[y, -1.6e+57], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.15e+27], t$95$0, If[LessEqual[y, -2.8e-49], N[(y * z), $MachinePrecision], If[LessEqual[y, 7.8e-84], x, If[LessEqual[y, 3.9e-41], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.45e-14], x, N[(y * z), $MachinePrecision]]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -2.7 \cdot 10^{+229}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.7 \cdot 10^{+207}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{+133}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{+57}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{+27}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.8 \cdot 10^{-49}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{-84}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.9 \cdot 10^{-41}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.45 \cdot 10^{-14}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -2.7e229 or -1.6999999999999999e207 < y < -1.14999999999999995e133 or -1.60000000000000015e57 < y < -1.15e27Initial program 100.0%
Taylor expanded in z around 0 79.0%
mul-1-neg79.0%
distribute-lft-neg-out79.0%
*-commutative79.0%
Simplified79.0%
Taylor expanded in y around inf 79.0%
associate-*r*79.0%
mul-1-neg79.0%
Simplified79.0%
if -2.7e229 < y < -1.6999999999999999e207 or -1.14999999999999995e133 < y < -1.60000000000000015e57 or -1.15e27 < y < -2.79999999999999997e-49 or 7.80000000000000045e-84 < y < 3.89999999999999991e-41 or 2.44999999999999997e-14 < y Initial program 100.0%
Taylor expanded in z around inf 77.6%
Taylor expanded in x around 0 73.1%
if -2.79999999999999997e-49 < y < 7.80000000000000045e-84 or 3.89999999999999991e-41 < y < 2.44999999999999997e-14Initial program 100.0%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around inf 76.3%
Final simplification75.2%
(FPCore (x y z)
:precision binary64
(if (<= y -2.95e-49)
(* y z)
(if (<= y 8e-84)
x
(if (<= y 8.2e-42) (* y z) (if (<= y 7.9e-13) x (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.95e-49) {
tmp = y * z;
} else if (y <= 8e-84) {
tmp = x;
} else if (y <= 8.2e-42) {
tmp = y * z;
} else if (y <= 7.9e-13) {
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 <= (-2.95d-49)) then
tmp = y * z
else if (y <= 8d-84) then
tmp = x
else if (y <= 8.2d-42) then
tmp = y * z
else if (y <= 7.9d-13) 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 <= -2.95e-49) {
tmp = y * z;
} else if (y <= 8e-84) {
tmp = x;
} else if (y <= 8.2e-42) {
tmp = y * z;
} else if (y <= 7.9e-13) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.95e-49: tmp = y * z elif y <= 8e-84: tmp = x elif y <= 8.2e-42: tmp = y * z elif y <= 7.9e-13: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.95e-49) tmp = Float64(y * z); elseif (y <= 8e-84) tmp = x; elseif (y <= 8.2e-42) tmp = Float64(y * z); elseif (y <= 7.9e-13) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.95e-49) tmp = y * z; elseif (y <= 8e-84) tmp = x; elseif (y <= 8.2e-42) tmp = y * z; elseif (y <= 7.9e-13) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.95e-49], N[(y * z), $MachinePrecision], If[LessEqual[y, 8e-84], x, If[LessEqual[y, 8.2e-42], N[(y * z), $MachinePrecision], If[LessEqual[y, 7.9e-13], x, N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.95 \cdot 10^{-49}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-84}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{-42}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 7.9 \cdot 10^{-13}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -2.95000000000000018e-49 or 8.0000000000000003e-84 < y < 8.2000000000000003e-42 or 7.89999999999999966e-13 < y Initial program 100.0%
Taylor expanded in z around inf 66.2%
Taylor expanded in x around 0 62.5%
if -2.95000000000000018e-49 < y < 8.0000000000000003e-84 or 8.2000000000000003e-42 < y < 7.89999999999999966e-13Initial program 100.0%
Taylor expanded in z around inf 99.9%
Taylor expanded in x around inf 76.3%
Final simplification67.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.45e+111) (not (<= x 7.5e+15))) (- x (* x y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.45e+111) || !(x <= 7.5e+15)) {
tmp = x - (x * y);
} 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.45d+111)) .or. (.not. (x <= 7.5d+15))) then
tmp = x - (x * y)
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.45e+111) || !(x <= 7.5e+15)) {
tmp = x - (x * y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.45e+111) or not (x <= 7.5e+15): tmp = x - (x * y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.45e+111) || !(x <= 7.5e+15)) tmp = Float64(x - Float64(x * y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.45e+111) || ~((x <= 7.5e+15))) tmp = x - (x * y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.45e+111], N[Not[LessEqual[x, 7.5e+15]], $MachinePrecision]], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{+111} \lor \neg \left(x \leq 7.5 \cdot 10^{+15}\right):\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.45e111 or 7.5e15 < x Initial program 100.0%
Taylor expanded in z around 0 91.9%
mul-1-neg91.9%
distribute-lft-neg-out91.9%
*-commutative91.9%
Simplified91.9%
Taylor expanded in x around 0 91.9%
neg-mul-191.9%
distribute-rgt-in91.9%
*-lft-identity91.9%
cancel-sign-sub-inv91.9%
Simplified91.9%
if -1.45e111 < x < 7.5e15Initial program 100.0%
Taylor expanded in z around inf 89.7%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return x + (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 = x + (y * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 79.1%
Final simplification79.1%
(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 z around inf 79.1%
Taylor expanded in x around inf 33.4%
Final simplification33.4%
herbie shell --seed 2023290
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))