
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + 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 * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
+-commutative98.8%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.35e+25)
(* x z)
(if (<= x -6.5e-7)
(* x y)
(if (<= x 6.5e-13) (- z) (if (<= x 3.4e+47) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.35e+25) {
tmp = x * z;
} else if (x <= -6.5e-7) {
tmp = x * y;
} else if (x <= 6.5e-13) {
tmp = -z;
} else if (x <= 3.4e+47) {
tmp = x * y;
} else {
tmp = x * 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.35d+25)) then
tmp = x * z
else if (x <= (-6.5d-7)) then
tmp = x * y
else if (x <= 6.5d-13) then
tmp = -z
else if (x <= 3.4d+47) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.35e+25) {
tmp = x * z;
} else if (x <= -6.5e-7) {
tmp = x * y;
} else if (x <= 6.5e-13) {
tmp = -z;
} else if (x <= 3.4e+47) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.35e+25: tmp = x * z elif x <= -6.5e-7: tmp = x * y elif x <= 6.5e-13: tmp = -z elif x <= 3.4e+47: tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.35e+25) tmp = Float64(x * z); elseif (x <= -6.5e-7) tmp = Float64(x * y); elseif (x <= 6.5e-13) tmp = Float64(-z); elseif (x <= 3.4e+47) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.35e+25) tmp = x * z; elseif (x <= -6.5e-7) tmp = x * y; elseif (x <= 6.5e-13) tmp = -z; elseif (x <= 3.4e+47) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.35e+25], N[(x * z), $MachinePrecision], If[LessEqual[x, -6.5e-7], N[(x * y), $MachinePrecision], If[LessEqual[x, 6.5e-13], (-z), If[LessEqual[x, 3.4e+47], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{+25}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -6.5 \cdot 10^{-7}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{-13}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3.4 \cdot 10^{+47}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.35e25 or 3.3999999999999998e47 < x Initial program 97.0%
*-commutative97.0%
sub-neg97.0%
distribute-rgt-in97.0%
metadata-eval97.0%
neg-mul-197.0%
associate-+r+97.0%
unsub-neg97.0%
+-commutative97.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 65.7%
Taylor expanded in x around inf 65.7%
*-commutative65.7%
Simplified65.7%
if -1.35e25 < x < -6.50000000000000024e-7 or 6.49999999999999957e-13 < x < 3.3999999999999998e47Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 79.4%
Taylor expanded in x around inf 76.1%
if -6.50000000000000024e-7 < x < 6.49999999999999957e-13Initial program 100.0%
+-commutative100.0%
fma-define100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 76.0%
mul-1-neg76.0%
Simplified76.0%
Final simplification72.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.4e+22) (not (<= x 3.4e+47))) (* x z) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e+22) || !(x <= 3.4e+47)) {
tmp = 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 ((x <= (-3.4d+22)) .or. (.not. (x <= 3.4d+47))) then
tmp = 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 ((x <= -3.4e+22) || !(x <= 3.4e+47)) {
tmp = x * z;
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.4e+22) or not (x <= 3.4e+47): tmp = x * z else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.4e+22) || !(x <= 3.4e+47)) tmp = Float64(x * z); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.4e+22) || ~((x <= 3.4e+47))) tmp = x * z; else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.4e+22], N[Not[LessEqual[x, 3.4e+47]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.4 \cdot 10^{+22} \lor \neg \left(x \leq 3.4 \cdot 10^{+47}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -3.4e22 or 3.3999999999999998e47 < x Initial program 97.0%
*-commutative97.0%
sub-neg97.0%
distribute-rgt-in97.0%
metadata-eval97.0%
neg-mul-197.0%
associate-+r+97.0%
unsub-neg97.0%
+-commutative97.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 65.7%
Taylor expanded in x around inf 65.7%
*-commutative65.7%
Simplified65.7%
if -3.4e22 < x < 3.3999999999999998e47Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 96.8%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0122) (not (<= y 1.12e-76))) (- (* x y) z) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0122) || !(y <= 1.12e-76)) {
tmp = (x * y) - z;
} else {
tmp = (x * z) - 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 <= (-0.0122d0)) .or. (.not. (y <= 1.12d-76))) then
tmp = (x * y) - z
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0122) || !(y <= 1.12e-76)) {
tmp = (x * y) - z;
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0122) or not (y <= 1.12e-76): tmp = (x * y) - z else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0122) || !(y <= 1.12e-76)) tmp = Float64(Float64(x * y) - z); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0122) || ~((y <= 1.12e-76))) tmp = (x * y) - z; else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0122], N[Not[LessEqual[y, 1.12e-76]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0122 \lor \neg \left(y \leq 1.12 \cdot 10^{-76}\right):\\
\;\;\;\;x \cdot y - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if y < -0.0122000000000000008 or 1.12e-76 < y Initial program 97.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
metadata-eval97.6%
neg-mul-197.6%
associate-+r+97.6%
unsub-neg97.6%
+-commutative97.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 91.5%
if -0.0122000000000000008 < y < 1.12e-76Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 91.5%
Final simplification91.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.35e-9) (not (<= x 8.5e-16))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.35e-9) || !(x <= 8.5e-16)) {
tmp = x * y;
} else {
tmp = -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.35d-9)) .or. (.not. (x <= 8.5d-16))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.35e-9) || !(x <= 8.5e-16)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.35e-9) or not (x <= 8.5e-16): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.35e-9) || !(x <= 8.5e-16)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.35e-9) || ~((x <= 8.5e-16))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.35e-9], N[Not[LessEqual[x, 8.5e-16]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{-9} \lor \neg \left(x \leq 8.5 \cdot 10^{-16}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.3500000000000001e-9 or 8.5000000000000001e-16 < x Initial program 97.5%
*-commutative97.5%
sub-neg97.5%
distribute-rgt-in97.5%
metadata-eval97.5%
neg-mul-197.5%
associate-+r+97.5%
unsub-neg97.5%
+-commutative97.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 45.3%
Taylor expanded in x around inf 44.6%
if -1.3500000000000001e-9 < x < 8.5000000000000001e-16Initial program 100.0%
+-commutative100.0%
fma-define100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 76.0%
mul-1-neg76.0%
Simplified76.0%
Final simplification61.0%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.8%
+-commutative98.8%
fma-define99.6%
sub-neg99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in x around 0 41.4%
mul-1-neg41.4%
Simplified41.4%
Final simplification41.4%
herbie shell --seed 2024054
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))