
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * 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 - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * 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 - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (- y x) z x))
double code(double x, double y, double z) {
return fma((y - x), z, x);
}
function code(x, y, z) return fma(Float64(y - x), z, x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, z, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -4.2e+210)
t_0
(if (<= z -1.5e+112)
(* y z)
(if (<= z -4e+20)
t_0
(if (<= z -8e-110)
(* y z)
(if (<= z 6.4e-58) x (if (<= z 1.12e+15) (* y z) t_0))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -4.2e+210) {
tmp = t_0;
} else if (z <= -1.5e+112) {
tmp = y * z;
} else if (z <= -4e+20) {
tmp = t_0;
} else if (z <= -8e-110) {
tmp = y * z;
} else if (z <= 6.4e-58) {
tmp = x;
} else if (z <= 1.12e+15) {
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 * -z
if (z <= (-4.2d+210)) then
tmp = t_0
else if (z <= (-1.5d+112)) then
tmp = y * z
else if (z <= (-4d+20)) then
tmp = t_0
else if (z <= (-8d-110)) then
tmp = y * z
else if (z <= 6.4d-58) then
tmp = x
else if (z <= 1.12d+15) 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 * -z;
double tmp;
if (z <= -4.2e+210) {
tmp = t_0;
} else if (z <= -1.5e+112) {
tmp = y * z;
} else if (z <= -4e+20) {
tmp = t_0;
} else if (z <= -8e-110) {
tmp = y * z;
} else if (z <= 6.4e-58) {
tmp = x;
} else if (z <= 1.12e+15) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -4.2e+210: tmp = t_0 elif z <= -1.5e+112: tmp = y * z elif z <= -4e+20: tmp = t_0 elif z <= -8e-110: tmp = y * z elif z <= 6.4e-58: tmp = x elif z <= 1.12e+15: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -4.2e+210) tmp = t_0; elseif (z <= -1.5e+112) tmp = Float64(y * z); elseif (z <= -4e+20) tmp = t_0; elseif (z <= -8e-110) tmp = Float64(y * z); elseif (z <= 6.4e-58) tmp = x; elseif (z <= 1.12e+15) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -4.2e+210) tmp = t_0; elseif (z <= -1.5e+112) tmp = y * z; elseif (z <= -4e+20) tmp = t_0; elseif (z <= -8e-110) tmp = y * z; elseif (z <= 6.4e-58) tmp = x; elseif (z <= 1.12e+15) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -4.2e+210], t$95$0, If[LessEqual[z, -1.5e+112], N[(y * z), $MachinePrecision], If[LessEqual[z, -4e+20], t$95$0, If[LessEqual[z, -8e-110], N[(y * z), $MachinePrecision], If[LessEqual[z, 6.4e-58], x, If[LessEqual[z, 1.12e+15], N[(y * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -4.2 \cdot 10^{+210}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.5 \cdot 10^{+112}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -4 \cdot 10^{+20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -8 \cdot 10^{-110}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 6.4 \cdot 10^{-58}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.12 \cdot 10^{+15}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -4.1999999999999997e210 or -1.4999999999999999e112 < z < -4e20 or 1.12e15 < z Initial program 100.0%
Taylor expanded in x around 0 99.0%
Taylor expanded in z around inf 99.0%
mul-1-neg99.0%
*-commutative99.0%
distribute-rgt-neg-in99.0%
Simplified99.0%
Taylor expanded in x around inf 97.2%
+-commutative97.2%
mul-1-neg97.2%
sub-neg97.2%
Simplified97.2%
Taylor expanded in x around inf 62.7%
associate-*r*62.7%
neg-mul-162.7%
*-commutative62.7%
Simplified62.7%
if -4.1999999999999997e210 < z < -1.4999999999999999e112 or -4e20 < z < -8.0000000000000004e-110 or 6.4000000000000002e-58 < z < 1.12e15Initial program 99.9%
Taylor expanded in x around 0 65.9%
if -8.0000000000000004e-110 < z < 6.4000000000000002e-58Initial program 100.0%
Taylor expanded in z around 0 77.0%
Final simplification68.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.5) (not (<= z 4.7e-7))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.5) || !(z <= 4.7e-7)) {
tmp = (y - x) * z;
} 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 ((z <= (-2.5d0)) .or. (.not. (z <= 4.7d-7))) then
tmp = (y - x) * z
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.5) || !(z <= 4.7e-7)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.5) or not (z <= 4.7e-7): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.5) || !(z <= 4.7e-7)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.5) || ~((z <= 4.7e-7))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.5], N[Not[LessEqual[z, 4.7e-7]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.5 \lor \neg \left(z \leq 4.7 \cdot 10^{-7}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -2.5 or 4.7e-7 < z Initial program 100.0%
Taylor expanded in z around inf 99.1%
if -2.5 < z < 4.7e-7Initial program 100.0%
Taylor expanded in y around inf 98.9%
*-commutative98.9%
Simplified98.9%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -8e-110) (not (<= z 6.5e-58))) (* (- y x) z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8e-110) || !(z <= 6.5e-58)) {
tmp = (y - x) * 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 ((z <= (-8d-110)) .or. (.not. (z <= 6.5d-58))) then
tmp = (y - x) * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8e-110) || !(z <= 6.5e-58)) {
tmp = (y - x) * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8e-110) or not (z <= 6.5e-58): tmp = (y - x) * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8e-110) || !(z <= 6.5e-58)) tmp = Float64(Float64(y - x) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8e-110) || ~((z <= 6.5e-58))) tmp = (y - x) * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8e-110], N[Not[LessEqual[z, 6.5e-58]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8 \cdot 10^{-110} \lor \neg \left(z \leq 6.5 \cdot 10^{-58}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -8.0000000000000004e-110 or 6.49999999999999964e-58 < z Initial program 100.0%
Taylor expanded in z around inf 94.4%
if -8.0000000000000004e-110 < z < 6.49999999999999964e-58Initial program 100.0%
Taylor expanded in z around 0 77.0%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.5e-110) (not (<= z 2.2e-58))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.5e-110) || !(z <= 2.2e-58)) {
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 ((z <= (-5.5d-110)) .or. (.not. (z <= 2.2d-58))) 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 ((z <= -5.5e-110) || !(z <= 2.2e-58)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.5e-110) or not (z <= 2.2e-58): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.5e-110) || !(z <= 2.2e-58)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.5e-110) || ~((z <= 2.2e-58))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.5e-110], N[Not[LessEqual[z, 2.2e-58]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{-110} \lor \neg \left(z \leq 2.2 \cdot 10^{-58}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -5.4999999999999998e-110 or 2.20000000000000006e-58 < z Initial program 100.0%
Taylor expanded in x around 0 51.5%
if -5.4999999999999998e-110 < z < 2.20000000000000006e-58Initial program 100.0%
Taylor expanded in z around 0 77.0%
Final simplification60.0%
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * 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 - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
Initial program 100.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 z around 0 30.7%
herbie shell --seed 2024097
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))