
(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 5 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 (if (or (<= x -3.05e+16) (not (<= x 1.5e+16))) (- x (* x y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.05e+16) || !(x <= 1.5e+16)) {
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 <= (-3.05d+16)) .or. (.not. (x <= 1.5d+16))) 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 <= -3.05e+16) || !(x <= 1.5e+16)) {
tmp = x - (x * y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.05e+16) or not (x <= 1.5e+16): tmp = x - (x * y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.05e+16) || !(x <= 1.5e+16)) 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 <= -3.05e+16) || ~((x <= 1.5e+16))) tmp = x - (x * y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.05e+16], N[Not[LessEqual[x, 1.5e+16]], $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 -3.05 \cdot 10^{+16} \lor \neg \left(x \leq 1.5 \cdot 10^{+16}\right):\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -3.05e16 or 1.5e16 < x Initial program 100.0%
Taylor expanded in z around 0 90.5%
mul-1-neg90.5%
distribute-lft-neg-out90.5%
*-commutative90.5%
Simplified90.5%
if -3.05e16 < x < 1.5e16Initial program 100.0%
Taylor expanded in z around inf 85.8%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.46e-49) (not (<= y 1.75e-78))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.46e-49) || !(y <= 1.75e-78)) {
tmp = y * z;
} 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.46d-49)) .or. (.not. (y <= 1.75d-78))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.46e-49) || !(y <= 1.75e-78)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.46e-49) or not (y <= 1.75e-78): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.46e-49) || !(y <= 1.75e-78)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.46e-49) || ~((y <= 1.75e-78))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.46e-49], N[Not[LessEqual[y, 1.75e-78]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.46 \cdot 10^{-49} \lor \neg \left(y \leq 1.75 \cdot 10^{-78}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.46000000000000007e-49 or 1.75e-78 < y Initial program 100.0%
Taylor expanded in z around inf 55.8%
Taylor expanded in x around 0 48.4%
if -1.46000000000000007e-49 < y < 1.75e-78Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in x around inf 77.4%
Final simplification60.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 74.3%
Final simplification74.3%
(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 74.3%
Taylor expanded in x around inf 38.3%
Final simplification38.3%
herbie shell --seed 2024059
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))