
(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 (<= z -1.35e-31) (not (<= z 3.2e-25))) (+ x (* y z)) (- x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.35e-31) || !(z <= 3.2e-25)) {
tmp = x + (y * z);
} else {
tmp = x - (x * 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 ((z <= (-1.35d-31)) .or. (.not. (z <= 3.2d-25))) then
tmp = x + (y * z)
else
tmp = x - (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.35e-31) || !(z <= 3.2e-25)) {
tmp = x + (y * z);
} else {
tmp = x - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.35e-31) or not (z <= 3.2e-25): tmp = x + (y * z) else: tmp = x - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.35e-31) || !(z <= 3.2e-25)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.35e-31) || ~((z <= 3.2e-25))) tmp = x + (y * z); else tmp = x - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.35e-31], N[Not[LessEqual[z, 3.2e-25]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{-31} \lor \neg \left(z \leq 3.2 \cdot 10^{-25}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot y\\
\end{array}
\end{array}
if z < -1.35000000000000007e-31 or 3.2000000000000001e-25 < z Initial program 100.0%
Taylor expanded in z around inf 94.6%
if -1.35000000000000007e-31 < z < 3.2000000000000001e-25Initial program 100.0%
Taylor expanded in z around 0 86.7%
mul-1-neg86.7%
distribute-rgt-neg-out86.7%
Simplified86.7%
Taylor expanded in x around 0 86.6%
neg-mul-186.6%
+-commutative86.6%
distribute-rgt1-in86.7%
cancel-sign-sub-inv86.7%
Simplified86.7%
Final simplification90.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -16000000000.0) (not (<= y 1.0))) (* y (- x)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -16000000000.0) || !(y <= 1.0)) {
tmp = y * -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 <= (-16000000000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * -x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -16000000000.0) || !(y <= 1.0)) {
tmp = y * -x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -16000000000.0) or not (y <= 1.0): tmp = y * -x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -16000000000.0) || !(y <= 1.0)) tmp = Float64(y * Float64(-x)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -16000000000.0) || ~((y <= 1.0))) tmp = y * -x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -16000000000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * (-x)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -16000000000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.6e10 or 1 < y Initial program 100.0%
Taylor expanded in z around 0 44.3%
mul-1-neg44.3%
distribute-rgt-neg-out44.3%
Simplified44.3%
Taylor expanded in y around inf 44.0%
associate-*r*44.0%
neg-mul-144.0%
Simplified44.0%
if -1.6e10 < y < 1Initial program 100.0%
Taylor expanded in z around 0 68.1%
mul-1-neg68.1%
distribute-rgt-neg-out68.1%
Simplified68.1%
Taylor expanded in y around 0 67.5%
Final simplification56.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.08e+151) (* y (- x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.08e+151) {
tmp = 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 (y <= (-1.08d+151)) then
tmp = 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 (y <= -1.08e+151) {
tmp = y * -x;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.08e+151: tmp = y * -x else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.08e+151) tmp = Float64(y * Float64(-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.08e+151) tmp = y * -x; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.08e+151], N[(y * (-x)), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.08 \cdot 10^{+151}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1.08000000000000003e151Initial program 100.0%
Taylor expanded in z around 0 62.7%
mul-1-neg62.7%
distribute-rgt-neg-out62.7%
Simplified62.7%
Taylor expanded in y around inf 62.7%
associate-*r*62.7%
neg-mul-162.7%
Simplified62.7%
if -1.08000000000000003e151 < y Initial program 100.0%
Taylor expanded in z around inf 85.4%
Final simplification82.7%
(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 0 56.8%
mul-1-neg56.8%
distribute-rgt-neg-out56.8%
Simplified56.8%
Taylor expanded in y around 0 36.7%
Final simplification36.7%
herbie shell --seed 2023195
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))